Skip to content

Commit bbff6c3

Browse files
committed
Added another ref.
1 parent 7647cb2 commit bbff6c3

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "dependencies/json11"]
88
path = dependencies/json11
99
url = https://github.com/dropbox/json11.git
10+
[submodule "dependencies/fastjson"]
11+
path = dependencies/fastjson
12+
url = https://github.com/mikeando/fastjson.git

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
.PHONY: clean cleandist
88

9-
CXXFLAGS = -std=c++11 -march=native -Wall -Wextra -Wshadow -Iinclude -Ibenchmark/linux -Idependencies/rapidjson/include -Idependencies/sajson/include -Idependencies/json11
9+
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
1010

1111
ifeq ($(SANITIZE),1)
1212
CXXFLAGS += -g3 -O0 -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
@@ -25,6 +25,7 @@ MINIFIERLIBFILES=src/jsonminifier.cpp
2525
RAPIDJSON_INCLUDE:=dependencies/rapidjson/include
2626
SAJSON_INCLUDE:=dependencies/sajson/include
2727
JSON11_INCLUDE:=dependencies/json11/json11.hpp
28+
FASTJSON_INCLUDE:=dependencies/include/fastjson/fastjson.h
2829

2930
LIBS=$(RAPIDJSON_INCLUDE) $(SAJSON_INCLUDE)
3031

@@ -49,6 +50,8 @@ $(RAPIDJSON_INCLUDE):
4950
$(JSON11_INCLUDE):
5051
git submodule update --init --recursive
5152

53+
$(FASTJSON_INCLUDE):
54+
git submodule update --init --recursive
5255

5356
bench: benchmarks/bench.cpp $(RAPIDJSON_INCLUDE) $(HEADERS)
5457
$(CXX) -std=c++11 -O3 -o $@ benchmarks/bench.cpp -I$(RAPIDJSON_INCLUDE) -Iinclude -march=native -lm -Wall -Wextra -Wno-narrowing

benchmark/parsingcompetition.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@
1111
#include "rapidjson/writer.h"
1212
#include "json11.cpp"
1313
#include "sajson.h"
14-
15-
14+
#include "fastjson.cpp"
15+
#include "fastjson_dom.cpp"
1616

1717

1818
using namespace rapidjson;
1919
using namespace std;
2020

21+
22+
// fastjson has a tricky interface
23+
void on_json_error( void *, const fastjson::ErrorContext& ec) {
24+
std::cerr<<"ERROR: "<<ec.mesg<<std::endl;
25+
}
26+
bool fastjson_parse(const char *input) {
27+
fastjson::Token token;
28+
fastjson::dom::Chunk chunk;
29+
std::string error_message;
30+
return fastjson::dom::parse_string(input, &token, &chunk, 0, &on_json_error, NULL);
31+
}
32+
2133
int main(int argc, char *argv[]) {
2234
if (argc < 2) {
2335
cerr << "Usage: " << argv[0] << " <jsonfile>\n";
@@ -49,7 +61,7 @@ int main(int argc, char *argv[]) {
4961

5062
int repeat = 10;
5163
int volume = p.second;
52-
BEST_TIME("json_parse", json_parse(p.first, p.second, pj), true, , repeat, volume, true);
64+
BEST_TIME("simdjson", json_parse(p.first, p.second, pj), true, , repeat, volume, true);
5365

5466
rapidjson::Document d;
5567

@@ -72,7 +84,7 @@ int main(int argc, char *argv[]) {
7284
std::string json11err;
7385
BEST_TIME("dropbox (json11) ", json11::Json::parse(buffer,json11err).is_null(), false, memcpy(buffer, p.first, p.second), repeat, volume, true);
7486

75-
free(buffer);
87+
BEST_TIME("fastjson ", fastjson_parse(buffer), true, memcpy(buffer, p.first, p.second), repeat, volume, true);
7688
free(p.first);
7789
free(ast_buffer);
7890
deallocate_ParsedJson(pj_ptr);

dependencies/fastjson

Submodule fastjson added at 485f994

0 commit comments

Comments
 (0)