]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/benchmarks/bench.cpp
Make @genericAppearance Doxygen macro consistent with @appearance.
[wxWidgets.git] / tests / benchmarks / bench.cpp
index c885d337edc9ab14fab216a65c6efc6529de6710..90b5f017e3bef0d7d6066a5cf3fbb1c4bcd9ae2a 100644 (file)
@@ -3,9 +3,8 @@
 // Purpose:     Main file of the benchmarking suite
 // Author:      Vadim Zeitlin
 // Created:     2008-07-19
-// RCS-ID:      $Id$
 // Copyright:   (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
 #include "wx/cmdline.h"
 #include "wx/stopwatch.h"
 
+#if wxUSE_GUI
+    #include "wx/frame.h"
+#endif
+
 #include "bench.h"
 
 // ----------------------------------------------------------------------------
@@ -27,6 +30,7 @@
 // ----------------------------------------------------------------------------
 
 static const char OPTION_LIST = 'l';
+static const char OPTION_SINGLE = '1';
 
 static const char OPTION_AVG_COUNT = 'a';
 static const char OPTION_NUM_RUNS = 'n';
@@ -124,6 +128,10 @@ void BenchApp::OnInitCmdLine(wxCmdLineParser& parser)
                      "list",
                      "list all the existing benchmarks");
 
+    parser.AddSwitch(OPTION_SINGLE,
+                     "single",
+                     "run the benchmark once only");
+
     parser.AddOption(OPTION_AVG_COUNT,
                      "avg-count",
                      wxString::Format
@@ -180,10 +188,25 @@ bool BenchApp::OnCmdLineParsed(wxCmdLineParser& parser)
         return false;
     }
 
-    parser.Found(OPTION_AVG_COUNT, &m_avgCount);
-    parser.Found(OPTION_NUM_RUNS, &m_numRuns);
+    bool numRunsSpecified = false;
+    if ( parser.Found(OPTION_AVG_COUNT, &m_avgCount) )
+        numRunsSpecified = true;
+    if ( parser.Found(OPTION_NUM_RUNS, &m_numRuns) )
+        numRunsSpecified = true;
     parser.Found(OPTION_NUMERIC_PARAM, &m_numParam);
     parser.Found(OPTION_STRING_PARAM, &m_strParam);
+    if ( parser.Found(OPTION_SINGLE) )
+    {
+        if ( numRunsSpecified )
+        {
+            wxFprintf(stderr, "Incompatible options specified.\n");
+
+            return false;
+        }
+
+        m_avgCount =
+        m_numRuns = 1;
+    }
 
     // construct sorted array for quick verification of benchmark names
     wxSortedArrayString benchmarks;
@@ -234,8 +257,8 @@ int BenchApp::OnRun()
         long timeMin = LONG_MAX,
              timeMax = 0,
              timeTotal = 0;
-        bool ok = true;
-        for ( long a = 0; a < m_avgCount; a++ )
+        bool ok = func->Init();
+        for ( long a = 0; ok && a < m_avgCount; a++ )
         {
             wxStopWatch sw;
             for ( long n = 0; n < m_numRuns && ok; n++ )
@@ -245,9 +268,6 @@ int BenchApp::OnRun()
 
             sw.Pause();
 
-            if ( !ok )
-                break;
-
             const long t = sw.Time();
             if ( t < timeMin )
                 timeMin = t;
@@ -256,6 +276,8 @@ int BenchApp::OnRun()
             timeTotal += t;
         }
 
+        func->Done();
+
         if ( !ok )
         {
             wxPrintf("ERROR\n");
@@ -275,6 +297,8 @@ int BenchApp::OnRun()
             wxPrintf("%.2f avg (min=%ld, max=%ld)\n",
                      (float)timeTotal / times, timeMin, timeMax);
         }
+
+        fflush(stdout);
     }
 
     return rc;