]> https://gitweb.dealii.org/ - dealii.git/commitdiff
timer check
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Wed, 16 Feb 2000 05:31:39 +0000 (05:31 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Wed, 16 Feb 2000 05:31:39 +0000 (05:31 +0000)
git-svn-id: https://svn.dealii.org/trunk@2411 0785d39b-7218-0410-832d-ea1e28bc413d

tests/base/Makefile
tests/base/timer.cc [new file with mode: 0644]
tests/base/timer.checked [new file with mode: 0644]

index e033fc3601e372777d2a19ea3534fba257354492..f276f0a3e6d86acd452e0fbcc2fe28e0fcc0791e 100644 (file)
@@ -59,7 +59,7 @@ endif
        @$(CXX) $(flags) -c $< -o $@
 
 
-all: logtest.check reference.check tensor.check quadrature_test.check
+all: logtest.check reference.check tensor.check quadrature_test.check timer.check
 exe: $(all:.check=.testcase)
 output: $(all:.check=.output)
 ############################################################
@@ -137,10 +137,18 @@ quadrature_test.testcase: $(quadrature_test-o-files) $(libraries)
        @$(CXX) $(flags) -o $@ $^
 
 
-############################################################
-# Continue with other targets if needed
-############################################################
 
+timer-cc-files = timer.cc
+
+ifeq ($(debug-mode),on)
+timer-o-files = $(timer-cc-files:.cc=.go)
+else
+timer-o-files = $(timer-cc-files:.cc=.o)
+endif
+
+timer.testcase: $(timer-o-files) $(libraries)
+       @echo =====linking======= $<
+       @$(CXX) $(flags) -o $@ $^
 
 ############################################################
 # Continue with other targets if needed
diff --git a/tests/base/timer.cc b/tests/base/timer.cc
new file mode 100644 (file)
index 0000000..3d0e092
--- /dev/null
@@ -0,0 +1,62 @@
+// $Id$
+// (c) Guido Kanschat, 2000
+
+#include <base/timer.h>
+#include <base/logstream.h>
+#include <fstream>
+
+// compute the ratio of two measurements and compare to
+// the expected value.
+
+void compare (double t1, double t2, double ratio)
+{
+  double r = t2/t1;
+  double d = fabs(r-ratio) / ratio;
+
+                                  // relative error < 10%?
+  if (d <= .1)
+    {
+      deallog << "OK" << endl;
+    } else {
+      deallog << "Ratio " << r << " should be " << ratio << endl;
+    }
+}
+
+// burn computer time
+
+void burn (unsigned int n)
+{
+  double s;
+  for (unsigned int i=0 ; i<n ; ++i)
+    {
+      for (unsigned int j=0 ; j<100000 ; ++j)
+       {
+         s += 1./j * i;
+       }
+    }
+}
+
+
+int main ()
+{
+  ofstream logfile("timer.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  Timer t1,t2;
+  burn (100);
+  double s01 = t1.stop();
+  double s02 = t2();
+  burn (100);
+  double s11 = t1.stop();
+  double s12 = t2();
+  t1.start();
+  burn (100);
+  double s21 = t1.stop();
+  double s22 = t2();
+
+  compare (s01,s02,1.);
+  compare (s11,s12,2.);
+  compare (s21,s22,3./2.);
+}
+
diff --git a/tests/base/timer.checked b/tests/base/timer.checked
new file mode 100644 (file)
index 0000000..fb71de2
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL::OK
+DEAL::OK
+DEAL::OK

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.