spreadsheet-load.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <xlnt/xlnt.hpp>
  2. #include <chrono>
  3. #include <helpers/path_helper.hpp>
  4. namespace {
  5. using milliseconds_d = std::chrono::duration<double, std::milli>;
  6. void run_load_test(const xlnt::path &file, int runs = 10)
  7. {
  8. std::cout << file.string() << "\n\n";
  9. xlnt::workbook wb;
  10. std::vector<std::chrono::steady_clock::duration> test_timings;
  11. for (int i = 0; i < runs; ++i)
  12. {
  13. auto start = std::chrono::steady_clock::now();
  14. wb.load(file);
  15. auto end = std::chrono::steady_clock::now();
  16. wb.clear();
  17. test_timings.push_back(end - start);
  18. std::cout << milliseconds_d(test_timings.back()).count() << " ms\n";
  19. }
  20. }
  21. void run_save_test(const xlnt::path &file, int runs = 10)
  22. {
  23. std::cout << file.string() << "\n\n";
  24. xlnt::workbook wb;
  25. wb.load(file);
  26. const xlnt::path save_path(file.filename());
  27. std::vector<std::chrono::steady_clock::duration> test_timings;
  28. for (int i = 0; i < runs; ++i)
  29. {
  30. auto start = std::chrono::steady_clock::now();
  31. wb.save(save_path);
  32. auto end = std::chrono::steady_clock::now();
  33. test_timings.push_back(end - start);
  34. std::cout << milliseconds_d(test_timings.back()).count() << " ms\n";
  35. }
  36. }
  37. } // namespace
  38. int main()
  39. {
  40. run_load_test(path_helper::benchmark_file("large.xlsx"));
  41. run_load_test(path_helper::benchmark_file("very_large.xlsx"));
  42. run_save_test(path_helper::benchmark_file("large.xlsx"));
  43. run_save_test(path_helper::benchmark_file("very_large.xlsx"));
  44. }