Skip to content

Commit

Permalink
added Benchpress benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Jun 2, 2015
1 parent f5470d4 commit cb873a4
Show file tree
Hide file tree
Showing 9 changed files with 67,754 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ json_unit
html

benchmark

json_benchmarks
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ all: json_unit

# clean up
clean:
rm -f json_unit
rm -f json_unit json_benchmarks

# build unit tests
json_unit: test/unit.cpp src/json.hpp test/catch.hpp
Expand All @@ -30,4 +30,9 @@ pretty:
--indent-col1-comments --pad-oper --pad-header --align-pointer=type \
--align-reference=type --add-brackets --convert-tabs --close-templates \
--lineend=linux --preserve-date --suffix=none \
src/json.hpp src/json.hpp.re2c test/unit.cpp
src/json.hpp src/json.hpp.re2c test/unit.cpp benchmarks/benchmarks.cpp

# benchmarks
json_benchmarks: benchmarks/benchmarks.cpp benchmarks/benchpress.hpp benchmarks/cxxopts.hpp
$(CXX) -std=c++11 $(CXXFLAGS) -O3 -flto -I src -I benchmarks $< $(LDFLAGS) -o $@
./json_benchmarks
71 changes: 71 additions & 0 deletions benchmarks/benchmarks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#define BENCHPRESS_CONFIG_MAIN

#include <fstream>
#include <benchpress.hpp>
#include <json.hpp>

BENCHMARK("parse jeopardy.json", [](benchpress::context* ctx)
{
for (size_t i = 0; i < ctx->num_iterations(); ++i)
{
std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json");
nlohmann::json j;
j << input_file;
}
})

BENCHMARK("parse canada.json", [](benchpress::context* ctx)
{
for (size_t i = 0; i < ctx->num_iterations(); ++i)
{
std::ifstream input_file("benchmarks/files/nativejson-benchmark/canada.json");
nlohmann::json j;
j << input_file;
}
})

BENCHMARK("parse citm_catalog.json", [](benchpress::context* ctx)
{
for (size_t i = 0; i < ctx->num_iterations(); ++i)
{
std::ifstream input_file("benchmarks/files/nativejson-benchmark/citm_catalog.json");
nlohmann::json j;
j << input_file;
}
})

BENCHMARK("parse twitter.json", [](benchpress::context* ctx)
{
for (size_t i = 0; i < ctx->num_iterations(); ++i)
{
std::ifstream input_file("benchmarks/files/nativejson-benchmark/twitter.json");
nlohmann::json j;
j << input_file;
}
})

BENCHMARK("dump jeopardy.json", [](benchpress::context* ctx)
{
std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json");
nlohmann::json j;
j << input_file;

ctx->reset_timer();
for (size_t i = 0; i < ctx->num_iterations(); ++i)
{
j.dump();
}
})

BENCHMARK("dump jeopardy.json with indent", [](benchpress::context* ctx)
{
std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json");
nlohmann::json j;
j << input_file;

ctx->reset_timer();
for (size_t i = 0; i < ctx->num_iterations(); ++i)
{
j.dump(4);
}
})
Loading

0 comments on commit cb873a4

Please sign in to comment.