add the possibility to pass numeric parameters to benchmark functions

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55332 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-08-28 17:14:39 +00:00
parent 3bbc1d95a1
commit 8fad8b2e52
3 changed files with 38 additions and 6 deletions

View File

@@ -30,6 +30,7 @@ static const char OPTION_LIST = 'l';
static const char OPTION_AVG_COUNT = 'a'; static const char OPTION_AVG_COUNT = 'a';
static const char OPTION_NUM_RUNS = 'n'; static const char OPTION_NUM_RUNS = 'n';
static const char OPTION_NUMERIC_PARAM = 'p';
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// BenchApp declaration // BenchApp declaration
@@ -53,6 +54,9 @@ public:
virtual int OnRun(); virtual int OnRun();
virtual int OnExit(); virtual int OnExit();
// accessor
int GetNumericParameter() const { return m_numParam; }
private: private:
// list all registered benchmarks // list all registered benchmarks
void ListBenchmarks(); void ListBenchmarks();
@@ -60,25 +64,32 @@ private:
// command lines options/parameters // command lines options/parameters
wxSortedArrayString m_toRun; wxSortedArrayString m_toRun;
long m_numRuns, long m_numRuns,
m_avgCount; m_avgCount,
m_numParam;
}; };
IMPLEMENT_APP_CONSOLE(BenchApp)
// ============================================================================ // ============================================================================
// Bench::Function implementation // Bench namespace symbols implementation
// ============================================================================ // ============================================================================
Bench::Function *Bench::Function::ms_head = NULL; Bench::Function *Bench::Function::ms_head = NULL;
long Bench::GetNumericParameter()
{
return wxGetApp().GetNumericParameter();
}
// ============================================================================ // ============================================================================
// BenchApp implementation // BenchApp implementation
// ============================================================================ // ============================================================================
IMPLEMENT_APP_CONSOLE(BenchApp)
BenchApp::BenchApp() BenchApp::BenchApp()
{ {
m_avgCount = 10; m_avgCount = 10;
m_numRuns = 10000; // just some default (TODO: switch to time-based one) m_numRuns = 10000; // just some default (TODO: switch to time-based one)
m_numParam = 1;
} }
bool BenchApp::OnInit() bool BenchApp::OnInit()
@@ -122,6 +133,12 @@ void BenchApp::OnInitCmdLine(wxCmdLineParser& parser)
m_numRuns m_numRuns
), ),
wxCMD_LINE_VAL_NUMBER); wxCMD_LINE_VAL_NUMBER);
parser.AddOption(OPTION_NUMERIC_PARAM,
"num-param",
"numeric parameter used by some benchmark functions "
"(default: 1)",
wxCMD_LINE_VAL_NUMBER);
parser.AddParam("benchmark name", parser.AddParam("benchmark name",
wxCMD_LINE_VAL_STRING, wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE); wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE);
@@ -148,6 +165,7 @@ bool BenchApp::OnCmdLineParsed(wxCmdLineParser& parser)
parser.Found(OPTION_AVG_COUNT, &m_avgCount); parser.Found(OPTION_AVG_COUNT, &m_avgCount);
parser.Found(OPTION_NUM_RUNS, &m_numRuns); parser.Found(OPTION_NUM_RUNS, &m_numRuns);
parser.Found(OPTION_NUMERIC_PARAM, &m_numParam);
// construct sorted array for quick verification of benchmark names // construct sorted array for quick verification of benchmark names
wxSortedArrayString benchmarks; wxSortedArrayString benchmarks;
@@ -183,7 +201,7 @@ int BenchApp::OnRun()
if ( m_toRun.Index(func->GetName()) == wxNOT_FOUND ) if ( m_toRun.Index(func->GetName()) == wxNOT_FOUND )
continue; continue;
wxPrintf("Benchmarking %s: ", func->GetName()); wxPrintf("Benchmarking %s(%ld): ", func->GetName(), m_numParam);
long timeMin = LONG_MAX, long timeMin = LONG_MAX,
timeMax = 0, timeMax = 0,

View File

@@ -63,6 +63,14 @@ private:
DECLARE_NO_COPY_CLASS(Function) DECLARE_NO_COPY_CLASS(Function)
}; };
/**
Get the numeric parameter.
Tests may use this parameter in whatever way they see fit, by default it is
1 but can be set to a different value by user from the command line.
*/
long GetNumericParameter();
} // namespace Bench } // namespace Bench
/** /**

View File

@@ -296,7 +296,13 @@ BENCHMARK_FUNC(ParseHTML)
static wxString html; static wxString html;
if ( html.empty() ) if ( html.empty() )
{ {
wxFFile("htmltest.html").ReadAll(&html, wxConvUTF8); wxString html1;
wxFFile("htmltest.html").ReadAll(&html1, wxConvUTF8);
// this is going to make for some invalid HTML, of course, but it
// doesn't really matter
for ( long n = 0; n < Bench::GetNumericParameter(); n++ )
html += html1;
} }
parser.Parse(html); parser.Parse(html);