]> git.saurik.com Git - wxWidgets.git/commitdiff
make the default value of numeric parameter 0, not 1, to make testing for it more...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 13 Oct 2008 22:25:51 +0000 (22:25 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 13 Oct 2008 22:25:51 +0000 (22:25 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56294 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/benchmarks/bench.cpp
tests/benchmarks/bench.h
tests/benchmarks/strings.cpp

index 9fe61f52fa974795fa64ac78c98d5c2b078e126b..c885d337edc9ab14fab216a65c6efc6529de6710 100644 (file)
@@ -31,6 +31,7 @@ static const char OPTION_LIST = 'l';
 static const char OPTION_AVG_COUNT = 'a';
 static const char OPTION_NUM_RUNS = 'n';
 static const char OPTION_NUMERIC_PARAM = 'p';
+static const char OPTION_STRING_PARAM = 's';
 
 // ----------------------------------------------------------------------------
 // BenchApp declaration
@@ -54,8 +55,9 @@ public:
     virtual int  OnRun();
     virtual int  OnExit();
 
-    // accessor
+    // accessors
     int GetNumericParameter() const { return m_numParam; }
+    const wxString& GetStringParameter() const { return m_strParam; }
 
 private:
     // list all registered benchmarks
@@ -66,6 +68,7 @@ private:
     long m_numRuns,
          m_avgCount,
          m_numParam;
+    wxString m_strParam;
 };
 
 IMPLEMENT_APP_CONSOLE(BenchApp)
@@ -81,6 +84,11 @@ long Bench::GetNumericParameter()
     return wxGetApp().GetNumericParameter();
 }
 
+wxString Bench::GetStringParameter()
+{
+    return wxGetApp().GetStringParameter();
+}
+
 // ============================================================================
 // BenchApp implementation
 // ============================================================================
@@ -89,7 +97,7 @@ BenchApp::BenchApp()
 {
     m_avgCount = 10;
     m_numRuns = 10000; // just some default (TODO: switch to time-based one)
-    m_numParam = 1;
+    m_numParam = 0;
 }
 
 bool BenchApp::OnInit()
@@ -135,9 +143,18 @@ void BenchApp::OnInitCmdLine(wxCmdLineParser& parser)
                      wxCMD_LINE_VAL_NUMBER);
     parser.AddOption(OPTION_NUMERIC_PARAM,
                      "num-param",
-                     "numeric parameter used by some benchmark functions "
-                     "(default: 1)",
+                     wxString::Format
+                     (
+                         "numeric parameter used by some benchmark functions "
+                         "(default: %ld)",
+                         m_numParam
+                     ),
                      wxCMD_LINE_VAL_NUMBER);
+    parser.AddOption(OPTION_STRING_PARAM,
+                     "str-param",
+                     "string parameter used by some benchmark functions "
+                     "(default: empty)",
+                     wxCMD_LINE_VAL_STRING);
 
     parser.AddParam("benchmark name",
                     wxCMD_LINE_VAL_STRING,
@@ -166,6 +183,7 @@ bool BenchApp::OnCmdLineParsed(wxCmdLineParser& parser)
     parser.Found(OPTION_AVG_COUNT, &m_avgCount);
     parser.Found(OPTION_NUM_RUNS, &m_numRuns);
     parser.Found(OPTION_NUMERIC_PARAM, &m_numParam);
+    parser.Found(OPTION_STRING_PARAM, &m_strParam);
 
     // construct sorted array for quick verification of benchmark names
     wxSortedArrayString benchmarks;
@@ -201,7 +219,17 @@ int BenchApp::OnRun()
         if ( m_toRun.Index(func->GetName()) == wxNOT_FOUND )
             continue;
 
-        wxPrintf("Benchmarking %s(%ld): ", func->GetName(), m_numParam);
+        wxString params;
+        if ( m_numParam )
+            params += wxString::Format(" with N=%ld", m_numParam);
+        if ( !m_strParam.empty() )
+        {
+            if ( !params.empty() )
+                params += " and";
+            params += wxString::Format(" with s=\"%s\"", m_strParam);
+        }
+
+        wxPrintf("Benchmarking %s%s: ", func->GetName(), params);
 
         long timeMin = LONG_MAX,
              timeMax = 0,
index eae52886f4ce7fbeae91c61d5fb5ddb4cb024353..21d95a4281e266343842303fc0c1832c56eaf82e 100644 (file)
@@ -71,6 +71,14 @@ private:
  */
 long GetNumericParameter();
 
+/**
+    Get the string parameter.
+
+    Tests may use this parameter in whatever way they see fit, by default it is
+    empty but can be set to a different value by user from the command line.
+ */
+wxString GetStringParameter();
+
 } // namespace Bench
 
 /**
index f8219729a2ae920d27f3f289a56853ff8d1364a4..9449f49110065268b08dda3264e22f8026143cbe 100644 (file)
@@ -48,7 +48,11 @@ const wxString& GetTestAsciiString()
     static wxString testString;
     if ( testString.empty() )
     {
-        for ( long n = 0; n < Bench::GetNumericParameter(); n++ )
+        long num = Bench::GetNumericParameter();
+        if ( !num )
+            num = 1;
+
+        for ( long n = 0; n < num; n++ )
             testString += wxString::FromAscii(asciistr);
     }
 
@@ -318,7 +322,11 @@ BENCHMARK_FUNC(ParseHTML)
 
         // 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++ )
+        long num = Bench::GetNumericParameter();
+        if ( !num )
+            num = 1;
+
+        for ( long n = 0; n < num; n++ )
             html += html1;
     }