From 138c90883b3a7bcb3cb08221030a2882083c2399 Mon Sep 17 00:00:00 2001 From: Crzyrndm Date: Sun, 29 Jul 2018 10:10:36 +1200 Subject: [PATCH] Modify writer benchmark to make comparisons between column and row usage - Cut time to write a sheet with many rows by not calling highest_row inside a loop over the rows (On^2 -> On) - Observation: more memory is used / cell as the number of rows increases --- benchmarks/writer.cpp | 31 +++++++++---------- source/detail/serialization/xlsx_producer.cpp | 3 +- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/benchmarks/writer.cpp b/benchmarks/writer.cpp index abe94e52..9e59f42e 100644 --- a/benchmarks/writer.cpp +++ b/benchmarks/writer.cpp @@ -39,11 +39,10 @@ void writer(int cols, int rows) for(int index = 0; index < rows; index++) { - if ((index + 1) % (rows / 10) == 0) + if (rows >= 10 && (index + 1) % (rows / 10) == 0) { std::string progress = std::string((index + 1) / (1 + rows / 10), '.'); std::cout << "\r" << progress; - std::cout.flush(); } for (int i = 0; i < cols; i++) @@ -51,8 +50,7 @@ void writer(int cols, int rows) ws.cell(xlnt::cell_reference(i + 1, index + 1)).value(i); } } - - std::cout << std::endl; + std::cout << '\n'; auto filename = "benchmark.xlsx"; wb.save(filename); @@ -63,33 +61,32 @@ void writer(int cols, int rows) // Time from the best of three is taken. void timer(std::function fn, int cols, int rows) { - using xlnt::benchmarks::current_time; - const auto repeat = std::size_t(3); - auto time = std::numeric_limits::max(); - + std::chrono::duration time{}; std::cout << cols << " cols " << rows << " rows" << std::endl; + fn(rows, cols); // 1 cold run for(int i = 0; i < repeat; i++) { - auto start = current_time(); + auto start = std::chrono::high_resolution_clock::now(); fn(cols, rows); - time = std::min(current_time() - start, time); + time += std::chrono::high_resolution_clock::now() - start; } - std::cout << time / 1000.0 << std::endl; + std::cout << time.count() / repeat << " seconds per iteration" << '\n' << '\n'; } } // namespace int main() { - timer(&writer, 100, 100); - timer(&writer, 1000, 100); - timer(&writer, 4000, 100); - timer(&writer, 8192, 100); - timer(&writer, 10, 10000); - timer(&writer, 4000, 1000); + timer(&writer, 160000, 1); + timer(&writer, 6400, 25); + timer(&writer, 1600, 100); + timer(&writer, 400, 400); + timer(&writer, 100, 1600); + timer(&writer, 25, 6400); + timer(&writer, 1, 160000); return 0; } diff --git a/source/detail/serialization/xlsx_producer.cpp b/source/detail/serialization/xlsx_producer.cpp index 212b0d89..94472a2f 100644 --- a/source/detail/serialization/xlsx_producer.cpp +++ b/source/detail/serialization/xlsx_producer.cpp @@ -2180,7 +2180,8 @@ void xlsx_producer::write_worksheet(const relationship &rel) return true; } - for (auto row = ws.lowest_row(); row <= ws.highest_row(); ++row) + auto highest = ws.highest_row(); + for (auto row = ws.lowest_row(); row <= highest; ++row) { if (ws.has_row_properties(row) && ws.row_properties(row).dy_descent.is_set()) {