diff --git a/README.md b/README.md index 6779542a..96f95d1d 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ bool is_ok = json_parse(p, pj); // do the parsing, return false on error ``` It is also possible to use a simply API if you do not mind having the overhead -of memory allocation: +of memory allocation with each new JSON document: ```C #include "simdjson/jsonparser.h" @@ -36,8 +36,6 @@ if( ! pj.isValid() ) { } ``` -ParsedJson build_parsed_json(const std::string_view &s) - ## Usage @@ -60,7 +58,7 @@ make parse To run comparative benchmarks (with other parsers): ``` -make parse +make parsingcompetition ./parsingcompetition jsonexamples/twitter.json ``` diff --git a/benchmark/parsingcompetition.cpp b/benchmark/parsingcompetition.cpp index 9bed0647..5125e601 100644 --- a/benchmark/parsingcompetition.cpp +++ b/benchmark/parsingcompetition.cpp @@ -88,8 +88,9 @@ int main(int argc, char *argv[]) { } int repeat = 10; int volume = p.size(); - BEST_TIME("simdjson", json_parse(p, pj), true, , repeat, volume, true); - BEST_TIME("simdjson (with dyn alloc) ", build_parsed_json(p).isValid(), true, , repeat, volume, true); + BEST_TIME("simdjson (dynamic mem) ", build_parsed_json(p).isValid(), true, , repeat, volume, true); + + BEST_TIME("simdjson (static alloc) ", json_parse(p, pj), true, , repeat, volume, true); rapidjson::Document d; @@ -123,3 +124,4 @@ int main(int argc, char *argv[]) { free(ast_buffer); free(buffer); } + diff --git a/include/simdjson/parsedjson.h b/include/simdjson/parsedjson.h index f5a4e804..aa8c55a3 100644 --- a/include/simdjson/parsedjson.h +++ b/include/simdjson/parsedjson.h @@ -51,14 +51,7 @@ public: n_structural_indexes = 0; u32 max_structures = ROUNDUP_N(len, 64) + 2 + 7; structural_indexes = new u32[max_structures]; - - if (structural_indexes == NULL) { - std::cerr << "Could not allocate memory for structural_indexes" - << std::endl; - delete[] structurals; - return false; - } - size_t localtapecapacity = ROUNDUP_N(len, 64); + size_t localtapecapacity = ROUNDUP_N(len / 2, 64); size_t localstringcapacity = ROUNDUP_N(len, 64); string_buf = new u8[localstringcapacity]; tape = new u64[localtapecapacity]; @@ -66,14 +59,14 @@ public: ret_address = new void *[maxdepth]; if ((string_buf == NULL) || (tape == NULL) || - (containing_scope_offset == NULL) || (ret_address == NULL)) { + (containing_scope_offset == NULL) || (ret_address == NULL) || (structural_indexes == NULL)) { std::cerr << "Could not allocate memory" << std::endl; delete[] ret_address; delete[] containing_scope_offset; delete[] tape; delete[] string_buf; delete[] structural_indexes; - delete[] structurals; + free(structurals); return false; }