Skip to content

Commit cb873a4

Browse files
committed
added Benchpress benchmarks
1 parent f5470d4 commit cb873a4

File tree

9 files changed

+67754
-2
lines changed

9 files changed

+67754
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ json_unit
22
html
33

44
benchmark
5+
6+
json_benchmarks

Makefile

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ all: json_unit
99

1010
# clean up
1111
clean:
12-
rm -f json_unit
12+
rm -f json_unit json_benchmarks
1313

1414
# build unit tests
1515
json_unit: test/unit.cpp src/json.hpp test/catch.hpp
@@ -30,4 +30,9 @@ pretty:
3030
--indent-col1-comments --pad-oper --pad-header --align-pointer=type \
3131
--align-reference=type --add-brackets --convert-tabs --close-templates \
3232
--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

benchmarks/benchmarks.cpp

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
})

0 commit comments

Comments
 (0)