1 2 #include "simdjson.h" 3 #include <chrono> 4 #include <cstring> 5 #include <iostream> 6 7 // Gigabyte: https://en.wikipedia.org/wiki/Gigabyte 8 simdjson_never_inline bench(std::string filename,simdjson::padded_string & p)9double bench(std::string filename, simdjson::padded_string& p) { 10 std::chrono::time_point<std::chrono::steady_clock> start_clock = 11 std::chrono::steady_clock::now(); 12 simdjson::padded_string::load(filename).value_unsafe().swap(p); 13 std::chrono::time_point<std::chrono::steady_clock> end_clock = 14 std::chrono::steady_clock::now(); 15 std::chrono::duration<double> elapsed = end_clock - start_clock; 16 return (static_cast<double>(p.size()) / (1000000000.)) / elapsed.count(); 17 } 18 main(int argc,char * argv[])19int main(int argc, char *argv[]) { 20 int optind = 1; 21 if (optind >= argc) { 22 std::cerr << "Reads document as far as possible. " << std::endl; 23 std::cerr << "Usage: " << argv[0] << " <jsonfile>" << std::endl; 24 exit(1); 25 } 26 const char *filename = argv[optind]; 27 if (optind + 1 < argc) { 28 std::cerr << "warning: ignoring everything after " << argv[optind + 1] 29 << std::endl; 30 } 31 simdjson::padded_string p; 32 bench(filename, p); 33 double meanval = 0; 34 double maxval = 0; 35 double minval = 10000; 36 std::cout << "file size: "<< (static_cast<double>(p.size()) / (1000000000.)) << " GB" <<std::endl; 37 size_t times = p.size() > 1000000000 ? 5 : 50; 38 #if __cpp_exceptions 39 try { 40 #endif 41 for(size_t i = 0; i < times; i++) { 42 double tval = bench(filename, p); 43 if(maxval < tval) maxval = tval; 44 if(minval > tval) minval = tval; 45 meanval += tval; 46 } 47 #if __cpp_exceptions 48 } catch (const std::exception &) { // caught by reference to base 49 std::cerr << "Could not load the file " << filename << std::endl; 50 return EXIT_FAILURE; 51 } 52 #endif 53 std::cout << "average speed: " << meanval / static_cast<double>(times) << " GB/s"<< std::endl; 54 std::cout << "min speed : " << minval << " GB/s" << std::endl; 55 std::cout << "max speed : " << maxval << " GB/s" << std::endl; 56 return EXIT_SUCCESS; 57 }