Performance

- Made Table::optimize a public method.
- Table::optimize called only from handleReportGHistory, where it's
  needed.
- Retaining benchmark.txt, to allow further improvements.
This commit is contained in:
Paul Beckingham 2009-03-08 21:29:55 -04:00
parent 0362b41f3b
commit 3f418c6fdc
4 changed files with 67 additions and 7 deletions

View file

@ -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;
}

View file

@ -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>&, std::string&);
void optimize (std::string&);
void sort (std::vector <int>&);
void clean (std::string&);

View file

@ -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;
}
////////////////////////////////////////////////////////////////////////////////

40
src/tests/benchmark.txt Normal file
View file

@ -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