Skip to content

Commit 286dadc

Browse files
author
Chedy Najjar
committed
add nlohmann to strategy files.
include it in the automated memory consumption bench.
1 parent 0decc91 commit 286dadc

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

benchmarks/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ add_executable(json_parser_th json_parser_th.cc utility.cc)
1616
target_link_libraries(json_parser_th simdjson stdc++fs)
1717

1818
add_executable(memory_bench_heaptrack memory_bench.cc utility.cc parsing_strategies.cc)
19-
target_link_libraries(memory_bench_heaptrack simdjson )
19+
target_link_libraries(memory_bench_heaptrack simdjson nlohmann_json::nlohmann_json)
2020

2121
add_executable(auto_memory_bench auto_memory_bench.cc utility.cc memorystat.cpp parsing_strategies.cc)
22-
target_link_libraries(auto_memory_bench simdjson stdc++fs)
22+
target_link_libraries(auto_memory_bench simdjson stdc++fs nlohmann_json::nlohmann_json)
2323

2424
add_compile_options(-pthread)
2525
add_executable(all_in_one single_gbench.cc utility.cc)

benchmarks/auto_memory_bench.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ int main(int argc, char *argv[]) {
7171
strategies.emplace_back("sajsonParseDynAllocMutBuff", sajsonParseDynAllocMutBuff);
7272
strategies.emplace_back("sajsonParseSngAllocMutBuff", sajsonParseSngAllocMutBuff);
7373

74+
strategies.emplace_back("nlohmannParse", nlohmannParse);
75+
7476
//TODOs:
7577
// validate arguments
7678
// set default path if none is provided

benchmarks/parsing_strategies.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,13 @@ bool sajsonParseSngAllocMutBuff(const char *filename) {
7777
const sajson::document document = sajson::parse(sajson::single_allocation(), sajson::mutable_string_view(length, buffer));
7878
delete[] buffer;
7979
return document.is_valid();
80+
}
81+
82+
//nlohmann
83+
84+
bool nlohmannParse(const char* filename){
85+
auto [buffer, length] = open_file(filename);
86+
auto j = json::parse(buffer, nullptr, false);
87+
delete[] buffer;
88+
return j.is_discarded();
8089
}

benchmarks/parsing_strategies.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
#include <simdjson/jsonparser.h>
44
#include <simdjson/jsonstream.h>
55
#include <rapidjson/document.h>
6+
#include <nlohmann/json.hpp>
67
#include <sajson.h>
78

89
#include "utility.h"
910

1011
using namespace simdjson;
12+
using json = nlohmann::json;
1113

1214
//SIMDJson
1315

@@ -31,4 +33,7 @@ bool sajsonParseSngAlloc(const char *filename);
3133

3234
bool sajsonParseDynAllocMutBuff(const char *filename);
3335

34-
bool sajsonParseSngAllocMutBuff(const char *filename);
36+
bool sajsonParseSngAllocMutBuff(const char *filename);
37+
38+
//Nlohmann
39+
bool nlohmannParse(const char* filename);

0 commit comments

Comments
 (0)