File tree 9 files changed +67754
-2
lines changed
9 files changed +67754
-2
lines changed Original file line number Diff line number Diff line change @@ -2,3 +2,5 @@ json_unit
2
2
html
3
3
4
4
benchmark
5
+
6
+ json_benchmarks
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ all: json_unit
9
9
10
10
# clean up
11
11
clean :
12
- rm -f json_unit
12
+ rm -f json_unit json_benchmarks
13
13
14
14
# build unit tests
15
15
json_unit : test/unit.cpp src/json.hpp test/catch.hpp
@@ -30,4 +30,9 @@ pretty:
30
30
--indent-col1-comments --pad-oper --pad-header --align-pointer=type \
31
31
--align-reference=type --add-brackets --convert-tabs --close-templates \
32
32
--lineend=linux --preserve-date --suffix=none \
33
- src/json.hpp src/json.hpp.re2c test/unit.cpp
33
+ src/json.hpp src/json.hpp.re2c test/unit.cpp benchmarks/benchmarks.cpp
34
+
35
+ # benchmarks
36
+ json_benchmarks : benchmarks/benchmarks.cpp benchmarks/benchpress.hpp benchmarks/cxxopts.hpp
37
+ $(CXX ) -std=c++11 $(CXXFLAGS ) -O3 -flto -I src -I benchmarks $< $(LDFLAGS ) -o $@
38
+ ./json_benchmarks
Original file line number Diff line number Diff line change
1
+ #define BENCHPRESS_CONFIG_MAIN
2
+
3
+ #include < fstream>
4
+ #include < benchpress.hpp>
5
+ #include < json.hpp>
6
+
7
+ BENCHMARK (" parse jeopardy.json" , [](benchpress::context* ctx)
8
+ {
9
+ for (size_t i = 0 ; i < ctx->num_iterations (); ++i)
10
+ {
11
+ std::ifstream input_file (" benchmarks/files/jeopardy/jeopardy.json" );
12
+ nlohmann::json j;
13
+ j << input_file;
14
+ }
15
+ })
16
+
17
+ BENCHMARK (" parse canada.json" , [](benchpress::context* ctx)
18
+ {
19
+ for (size_t i = 0 ; i < ctx->num_iterations (); ++i)
20
+ {
21
+ std::ifstream input_file (" benchmarks/files/nativejson-benchmark/canada.json" );
22
+ nlohmann::json j;
23
+ j << input_file;
24
+ }
25
+ })
26
+
27
+ BENCHMARK (" parse citm_catalog.json" , [](benchpress::context* ctx)
28
+ {
29
+ for (size_t i = 0 ; i < ctx->num_iterations (); ++i)
30
+ {
31
+ std::ifstream input_file (" benchmarks/files/nativejson-benchmark/citm_catalog.json" );
32
+ nlohmann::json j;
33
+ j << input_file;
34
+ }
35
+ })
36
+
37
+ BENCHMARK (" parse twitter.json" , [](benchpress::context* ctx)
38
+ {
39
+ for (size_t i = 0 ; i < ctx->num_iterations (); ++i)
40
+ {
41
+ std::ifstream input_file (" benchmarks/files/nativejson-benchmark/twitter.json" );
42
+ nlohmann::json j;
43
+ j << input_file;
44
+ }
45
+ })
46
+
47
+ BENCHMARK (" dump jeopardy.json" , [](benchpress::context* ctx)
48
+ {
49
+ std::ifstream input_file (" benchmarks/files/jeopardy/jeopardy.json" );
50
+ nlohmann::json j;
51
+ j << input_file;
52
+
53
+ ctx->reset_timer ();
54
+ for (size_t i = 0 ; i < ctx->num_iterations (); ++i)
55
+ {
56
+ j.dump ();
57
+ }
58
+ })
59
+
60
+ BENCHMARK (" dump jeopardy.json with indent" , [](benchpress::context* ctx)
61
+ {
62
+ std::ifstream input_file (" benchmarks/files/jeopardy/jeopardy.json" );
63
+ nlohmann::json j;
64
+ j << input_file;
65
+
66
+ ctx->reset_timer ();
67
+ for (size_t i = 0 ; i < ctx->num_iterations (); ++i)
68
+ {
69
+ j.dump (4 );
70
+ }
71
+ })
You can’t perform that action at this time.
0 commit comments