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
1818using namespace rapidjson ;
1919using 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+
2133int 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);
0 commit comments