diff --git a/.gitmodules b/.gitmodules index b54125d0..7605d627 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "dependencies/json11"] path = dependencies/json11 url = https://github.com/dropbox/json11.git +[submodule "dependencies/fastjson"] + path = dependencies/fastjson + url = https://github.com/mikeando/fastjson.git diff --git a/Makefile b/Makefile index 06413cfb..6c9ae45d 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ .PHONY: clean cleandist -CXXFLAGS = -std=c++11 -march=native -Wall -Wextra -Wshadow -Iinclude -Ibenchmark/linux -Idependencies/rapidjson/include -Idependencies/sajson/include -Idependencies/json11 +CXXFLAGS = -std=c++11 -march=native -Wall -Wextra -Wshadow -Iinclude -Ibenchmark/linux -Idependencies/rapidjson/include -Idependencies/sajson/include -Idependencies/json11 -Idependencies/fastjson/src -Idependencies/fastjson/include ifeq ($(SANITIZE),1) CXXFLAGS += -g3 -O0 -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined @@ -25,6 +25,7 @@ MINIFIERLIBFILES=src/jsonminifier.cpp RAPIDJSON_INCLUDE:=dependencies/rapidjson/include SAJSON_INCLUDE:=dependencies/sajson/include JSON11_INCLUDE:=dependencies/json11/json11.hpp +FASTJSON_INCLUDE:=dependencies/include/fastjson/fastjson.h LIBS=$(RAPIDJSON_INCLUDE) $(SAJSON_INCLUDE) @@ -49,6 +50,8 @@ $(RAPIDJSON_INCLUDE): $(JSON11_INCLUDE): git submodule update --init --recursive +$(FASTJSON_INCLUDE): + git submodule update --init --recursive bench: benchmarks/bench.cpp $(RAPIDJSON_INCLUDE) $(HEADERS) $(CXX) -std=c++11 -O3 -o $@ benchmarks/bench.cpp -I$(RAPIDJSON_INCLUDE) -Iinclude -march=native -lm -Wall -Wextra -Wno-narrowing diff --git a/benchmark/parsingcompetition.cpp b/benchmark/parsingcompetition.cpp index bfed68a6..1895f066 100644 --- a/benchmark/parsingcompetition.cpp +++ b/benchmark/parsingcompetition.cpp @@ -11,13 +11,25 @@ #include "rapidjson/writer.h" #include "json11.cpp" #include "sajson.h" - - +#include "fastjson.cpp" +#include "fastjson_dom.cpp" using namespace rapidjson; using namespace std; + +// fastjson has a tricky interface +void on_json_error( void *, const fastjson::ErrorContext& ec) { + std::cerr<<"ERROR: "<\n"; @@ -49,7 +61,7 @@ int main(int argc, char *argv[]) { int repeat = 10; int volume = p.second; - BEST_TIME("json_parse", json_parse(p.first, p.second, pj), true, , repeat, volume, true); + BEST_TIME("simdjson", json_parse(p.first, p.second, pj), true, , repeat, volume, true); rapidjson::Document d; @@ -72,7 +84,7 @@ int main(int argc, char *argv[]) { std::string json11err; BEST_TIME("dropbox (json11) ", json11::Json::parse(buffer,json11err).is_null(), false, memcpy(buffer, p.first, p.second), repeat, volume, true); - free(buffer); + BEST_TIME("fastjson ", fastjson_parse(buffer), true, memcpy(buffer, p.first, p.second), repeat, volume, true); free(p.first); free(ast_buffer); deallocate_ParsedJson(pj_ptr); diff --git a/dependencies/fastjson b/dependencies/fastjson new file mode 160000 index 00000000..485f994a --- /dev/null +++ b/dependencies/fastjson @@ -0,0 +1 @@ +Subproject commit 485f994a61a64ac73fa6a40d4d639b99b463563b