You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.0 KiB

  1. #define BENCHPRESS_CONFIG_MAIN
  2. #include <fstream>
  3. #include <benchpress.hpp>
  4. #include <json.hpp>
  5. BENCHMARK("parse jeopardy.json", [](benchpress::context* ctx)
  6. {
  7. for (size_t i = 0; i < ctx->num_iterations(); ++i)
  8. {
  9. std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json");
  10. nlohmann::json j;
  11. j << input_file;
  12. }
  13. })
  14. BENCHMARK("parse canada.json", [](benchpress::context* ctx)
  15. {
  16. for (size_t i = 0; i < ctx->num_iterations(); ++i)
  17. {
  18. std::ifstream input_file("benchmarks/files/nativejson-benchmark/canada.json");
  19. nlohmann::json j;
  20. j << input_file;
  21. }
  22. })
  23. BENCHMARK("parse citm_catalog.json", [](benchpress::context* ctx)
  24. {
  25. for (size_t i = 0; i < ctx->num_iterations(); ++i)
  26. {
  27. std::ifstream input_file("benchmarks/files/nativejson-benchmark/citm_catalog.json");
  28. nlohmann::json j;
  29. j << input_file;
  30. }
  31. })
  32. BENCHMARK("parse twitter.json", [](benchpress::context* ctx)
  33. {
  34. for (size_t i = 0; i < ctx->num_iterations(); ++i)
  35. {
  36. std::ifstream input_file("benchmarks/files/nativejson-benchmark/twitter.json");
  37. nlohmann::json j;
  38. j << input_file;
  39. }
  40. })
  41. BENCHMARK("dump jeopardy.json", [](benchpress::context* ctx)
  42. {
  43. std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json");
  44. nlohmann::json j;
  45. j << input_file;
  46. std::ofstream output_file("jeopardy.dump.json");
  47. ctx->reset_timer();
  48. for (size_t i = 0; i < ctx->num_iterations(); ++i)
  49. {
  50. output_file << j;
  51. }
  52. std::remove("jeopardy.dump.json");
  53. })
  54. BENCHMARK("dump jeopardy.json with indent", [](benchpress::context* ctx)
  55. {
  56. std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json");
  57. nlohmann::json j;
  58. j << input_file;
  59. std::ofstream output_file("jeopardy.dump.json");
  60. ctx->reset_timer();
  61. for (size_t i = 0; i < ctx->num_iterations(); ++i)
  62. {
  63. output_file << std::setw(4) << j;
  64. }
  65. std::remove("jeopardy.dump.json");
  66. })