From 4c98c971b838645416d7bac9de4e8a4d44e9d584 Mon Sep 17 00:00:00 2001 From: Niels Date: Wed, 20 Jul 2016 23:06:45 +0200 Subject: [PATCH] added benchmarks for numbers --- .gitignore | 2 ++ Makefile | 2 ++ benchmarks/benchmarks.cpp | 30 ++++++++++++++++++++++++++++ benchmarks/files/numbers/generate.py | 25 +++++++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100755 benchmarks/files/numbers/generate.py diff --git a/.gitignore b/.gitignore index d5bd2f7c..fd41a2e3 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ me.nlohmann.json.docset android doc/xml + +benchmarks/files/numbers/*.json diff --git a/Makefile b/Makefile index 56e46d14..98f07687 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ all: json_unit # clean up clean: rm -fr json_unit json_benchmarks fuzz fuzz-testing *.dSYM + rm -fr benchmarks/files/numbers/*.json $(MAKE) clean -Cdoc @@ -85,6 +86,7 @@ pretty: # benchmarks json_benchmarks: benchmarks/benchmarks.cpp benchmarks/benchpress.hpp benchmarks/cxxopts.hpp src/json.hpp + cd benchmarks/files/numbers ; python generate.py $(CXX) -std=c++11 $(CXXFLAGS) -O3 -flto -I src -I benchmarks $< $(LDFLAGS) -o $@ ./json_benchmarks diff --git a/benchmarks/benchmarks.cpp b/benchmarks/benchmarks.cpp index 1f5eb5e3..ec6b462c 100644 --- a/benchmarks/benchmarks.cpp +++ b/benchmarks/benchmarks.cpp @@ -44,6 +44,36 @@ BENCHMARK("parse twitter.json", [](benchpress::context* ctx) } }) +BENCHMARK("parse numbers/floats.json", [](benchpress::context* ctx) +{ + for (size_t i = 0; i < ctx->num_iterations(); ++i) + { + std::ifstream input_file("benchmarks/files/numbers/floats.json"); + nlohmann::json j; + j << input_file; + } +}) + +BENCHMARK("parse numbers/signed_ints.json", [](benchpress::context* ctx) +{ + for (size_t i = 0; i < ctx->num_iterations(); ++i) + { + std::ifstream input_file("benchmarks/files/numbers/signed_ints.json"); + nlohmann::json j; + j << input_file; + } +}) + +BENCHMARK("parse numbers/unsigned_ints.json", [](benchpress::context* ctx) +{ + for (size_t i = 0; i < ctx->num_iterations(); ++i) + { + std::ifstream input_file("benchmarks/files/numbers/unsigned_ints.json"); + nlohmann::json j; + j << input_file; + } +}) + BENCHMARK("dump jeopardy.json", [](benchpress::context* ctx) { std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json"); diff --git a/benchmarks/files/numbers/generate.py b/benchmarks/files/numbers/generate.py new file mode 100755 index 00000000..714ee3a1 --- /dev/null +++ b/benchmarks/files/numbers/generate.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +import json +import random +import sys + +random.seed(0) + +# floats +result_floats = [] +for x in range(0, 1000000): + result_floats.append(random.uniform(-100000000.0, 100000000.0)) +json.dump(result_floats, open("floats.json", "w"), indent=2) + +# unsigned integers +result_uints = [] +for x in range(0, 1000000): + result_uints.append(random.randint(0, 18446744073709551615)) +json.dump(result_uints, open("unsigned_ints.json", "w"), indent=2) + +# signed integers +result_sints = [] +for x in range(0, 1000000): + result_sints.append(random.randint(-9223372036854775808, 9223372036854775807)) +json.dump(result_sints, open("signed_ints.json", "w"), indent=2)