From 3f418c6fdc8e833c5d83a4e1d3d5975347246f13 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 8 Mar 2009 21:29:55 -0400 Subject: [PATCH] Performance - Made Table::optimize a public method. - Table::optimize called only from handleReportGHistory, where it's needed. - Retaining benchmark.txt, to allow further improvements. --- src/Table.cpp | 26 +++++++++++++++++++++----- src/Table.h | 2 +- src/report.cpp | 6 +++++- src/tests/benchmark.txt | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 src/tests/benchmark.txt diff --git a/src/Table.cpp b/src/Table.cpp index 26ed0bacb..cce934cfe 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -742,7 +742,7 @@ int Table::columnCount () // ^[[31mName^[[0m ^[[31mValue^[[0m -> ^[[31mName Value^[[0m // // This method is a work in progress. -void Table::optimize (std::string& output) +void Table::optimize (std::string& output) const { /* int start = output.length (); @@ -785,14 +785,32 @@ void Table::optimize (std::string& output) 'task ghistory' in 0 seconds Much better. Table::optimize is currently disabled. +*/ size_t i = 0; - while ((i = output.find (" \n")) != std::string::npos) + while ((i = output.find (" \n")) != std::string::npos) + { + output = output.substr (0, i) + + output.substr (i + 8, std::string::npos); + } + + while ((i = output.find (" \n")) != std::string::npos) + { + output = output.substr (0, i) + + output.substr (i + 4, std::string::npos); + } + + while ((i = output.find (" \n")) != std::string::npos) { output = output.substr (0, i) + output.substr (i + 2, std::string::npos); } -*/ + + while ((i = output.find (" \n")) != std::string::npos) + { + output = output.substr (0, i) + + output.substr (i + 1, std::string::npos); + } /* std::cout << int ((100 * (start - output.length ()) / start)) @@ -1066,8 +1084,6 @@ const std::string Table::render () output += "\n"; } - // Eliminate redundant color codes. - optimize (output); return output; } diff --git a/src/Table.h b/src/Table.h index e1d244e14..765c1116a 100644 --- a/src/Table.h +++ b/src/Table.h @@ -85,6 +85,7 @@ public: int rowCount (); int columnCount (); const std::string render (); + void optimize (std::string&) const; private: std::string getCell (const int, const int); @@ -101,7 +102,6 @@ private: const std::string formatHeader (const int, const int, const int); const std::string formatHeaderDashedUnderline (const int, const int, const int); void formatCell (const int, const int, const int, const int, std::vector &, std::string&); - void optimize (std::string&); void sort (std::vector &); void clean (std::string&); diff --git a/src/report.cpp b/src/report.cpp index a762a5c69..f6aa675ca 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -1205,7 +1205,11 @@ std::string handleReportGHistory (TDB& tdb, T& task, Config& conf) else out << "No tasks." << std::endl; - return out.str (); + // Eliminate redundant color codes. + std::string optimized = out.str (); + table.optimize (optimized); + + return optimized; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/tests/benchmark.txt b/src/tests/benchmark.txt new file mode 100644 index 000000000..78cfba505 --- /dev/null +++ b/src/tests/benchmark.txt @@ -0,0 +1,40 @@ +3/8/2009 + Before: + Table::render + 26.1792 + 16.67 + 18.9697 + 28.6328 + 1.86553 + 0.00044 + 0.000319 + --------- + 92.317989 + + After Table::optimize removed: + Table::render + 0.146177 + 0.145928 + 0.184444 + 0.014784 + 0.000512 + 0.000267 + --------- + 0.492112 + + Speedup: + 92.317989 / 0.492112 = 187.6 + +3/8/2009 + New benchmark: + 1..4 + ok 1 - Created bench.rc + # start=1236558734 + # 1000 tasks added in 3 seconds + # 600 tasks altered in 29 seconds + # stop=1236558924 + # total=190 + ok 2 - Removed pending.data + ok 3 - Removed completed.data + ok 4 - Removed bench.rc +