[cig-commits] r11685 - cs/benchmark/cigma/trunk/src/tests

luis at geodynamics.org luis at geodynamics.org
Tue Apr 1 01:40:02 PDT 2008


Author: luis
Date: 2008-04-01 01:40:02 -0700 (Tue, 01 Apr 2008)
New Revision: 11685

Added:
   cs/benchmark/cigma/trunk/src/tests/TestTimer.cpp
Modified:
   cs/benchmark/cigma/trunk/src/tests/Makefile
Log:
Added simple test of using a Timer on an otherwise empty loop


Modified: cs/benchmark/cigma/trunk/src/tests/Makefile
===================================================================
--- cs/benchmark/cigma/trunk/src/tests/Makefile	2008-04-01 03:41:29 UTC (rev 11684)
+++ cs/benchmark/cigma/trunk/src/tests/Makefile	2008-04-01 08:40:02 UTC (rev 11685)
@@ -23,6 +23,7 @@
 	TestHex.o \
 	TestPoints.o \
 	TestZeroField.o \
+	TestTimer.o \
 	TestStringUtils.o \
 
 

Added: cs/benchmark/cigma/trunk/src/tests/TestTimer.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/tests/TestTimer.cpp	                        (rev 0)
+++ cs/benchmark/cigma/trunk/src/tests/TestTimer.cpp	2008-04-01 08:40:02 UTC (rev 11685)
@@ -0,0 +1,54 @@
+#include <iostream>
+#include <string>
+#include "../Timer.h"
+#include "../StringUtils.h"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+    int nel = 1000000;
+    int freq = 100;
+
+    bool verbose = true;
+
+    
+    /* Convert argv[1] to string */
+    string f = "100";
+    if (argc > 1)
+    {
+        f = argv[1];
+    }
+
+    string_to_int(f,freq);
+
+    if (freq <= 0)
+    {
+        cerr << "Please specify a positive integer "
+             << "(got '" << f << "')" << endl;
+        return 1;
+    }
+
+    cout << "Timing empty loop:" << endl;
+    cout << "  output frequency = " << freq << endl;
+    cout << "  number of iterations = " << nel << endl;
+    cout << endl;
+
+    /* Time an empty loop */
+    Timer timer;
+    timer.print_header(cout, "e");
+    timer.start(nel);
+    timer.update(0);
+    for (int e = 0; e < nel; e++)
+    {
+        if (verbose && ((e+1) % freq == 0))
+        {
+            timer.update(e+1);
+            cout << timer;
+        }
+    }
+    timer.update(nel);
+    cout << timer << endl;
+
+    return 0;
+}



More information about the cig-commits mailing list