🚧 added size benchmark for binary formats

This commit is contained in:
Niels Lohmann 2018-01-10 23:13:48 +01:00
parent 3a7585e738
commit 10bad9381d
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
2 changed files with 39 additions and 1 deletions

View file

@ -17,5 +17,8 @@ json_benchmarks_simple: src/benchmarks_simple.cpp ../src/json.hpp
number_jsons:
(test -e files/numbers/floats.json -a -e files/numbers/signed_ints.json -a -e files/numbers/unsigned_ints.json) || (cd files/numbers ; python generate.py)
json_formats: src/formats.cpp ../src/json.hpp number_jsons
$(CXX) -std=c++11 $(CXXFLAGS) -DNDEBUG -O3 -flto -I../src $(<) $(LDFLAGS) -o $@
clean:
rm -f json_benchmarks json_benchmarks_simple files/numbers/*.json
rm -f json_benchmarks json_benchmarks_simple json_formats files/numbers/*.json

View file

@ -0,0 +1,35 @@
#include <json.hpp>
#include <fstream>
#include <iostream>
using json = nlohmann::json;
int main()
{
std::vector<std::string> files = {
"files/jeopardy/jeopardy.json",
"files/nativejson-benchmark/canada.json",
"files/nativejson-benchmark/citm_catalog.json",
"files/nativejson-benchmark/twitter.json",
"files/numbers/floats.json",
"files/numbers/signed_ints.json",
"files/numbers/unsigned_ints.json"
};
for (const auto& file: files)
{
std::ifstream f(file);
json j = json::parse(f);
auto v_cbor = json::to_cbor(j);
auto v_msgpack = json::to_msgpack(j);
auto v_ubjson = json::to_ubjson(j, true, true);
double baseline = j.dump().size();
std::cout << file << ", JSON: " << j.dump(2).size() << " " << j.dump(2).size()/baseline << std::endl;
std::cout << file << ", JSON (minified): " << j.dump().size() << std::endl;
std::cout << file << ", CBOR: " << v_cbor.size() << " " << v_cbor.size()/baseline << std::endl;
std::cout << file << ", MessagePack: " << v_msgpack.size() << " " << v_msgpack.size()/baseline << std::endl;
std::cout << file << ", UBJSON (optimized): " << v_ubjson.size() << " " << v_ubjson.size()/baseline << std::endl;
}
}