lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] (no subject)


From: Greg Chicares
Subject: [lmi-commits] (no subject)
Date: Sun, 19 Jun 2016 14:56:45 +0000 (UTC)

branch: master
commit 34e1fe654a5ef08c894d71d493074145977e26eb
Author: Gregory W. Chicares <address@hidden>
Date:   Sun Jun 19 14:56:16 2016 +0000

    Measure run time vs. double in currency unit test
---
 Makefile.am       |    3 ++-
 currency_test.cpp |   42 ++++++++++++++++++++++++++++++++++++++++++
 objects.make      |    1 +
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 0e185ba..5425e8b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -636,7 +636,8 @@ test_crc32_CXXFLAGS = $(AM_CXXFLAGS)
 
 test_currency_SOURCES = \
   $(common_test_objects) \
-  currency_test.cpp
+  currency_test.cpp \
+  timer.cpp
 test_currency_CXXFLAGS = $(AM_CXXFLAGS)
 
 test_expression_template_0_SOURCES = \
diff --git a/currency_test.cpp b/currency_test.cpp
index 2f6a9db..c22f4b6 100644
--- a/currency_test.cpp
+++ b/currency_test.cpp
@@ -24,6 +24,7 @@
 #include "currency.hpp"
 
 #include "test_tools.hpp"
+#include "timer.hpp"
 
 #include <limits>
 #include <sstream>
@@ -41,6 +42,7 @@ class currency_test
     static void test_arithmetic();
     static void test_double();
     static void test_streams();
+    static void test_speed();
 };
 
 void currency_test::test()
@@ -51,6 +53,7 @@ void currency_test::test()
     test_arithmetic();
     test_double();
     test_streams();
+    test_speed();
 }
 
 void currency_test::test_ctors()
@@ -174,6 +177,45 @@ void currency_test::test_streams()
     #undef TEST_ROUNDTRIP
 }
 
+template<typename T>
+void do_some_arithmetic(T t)
+{
+    T u(t);
+    t += u;
+    t += t;
+    t -= u;
+    t = t - u;
+    u = t;
+}
+
+void time_double()
+{
+    double d(1.23);
+    for(int j = 0; j < 1000000; ++j)
+        {
+        do_some_arithmetic(d);
+        }
+}
+
+void time_currency()
+{
+    currency c(1, 23);
+    for(int j = 0; j < 1000000; ++j)
+        {
+        do_some_arithmetic(c);
+        }
+}
+
+void currency_test::test_speed()
+{
+    std::cout
+        << "  Speed tests..."
+        << "\n  double  : " << TimeAnAliquot(time_double)
+        << "\n  currency: " << TimeAnAliquot(time_currency)
+        << std::endl
+        ;
+}
+
 int test_main(int, char*[])
 {
     currency_test::test();
diff --git a/objects.make b/objects.make
index 461da2b..100c33d 100644
--- a/objects.make
+++ b/objects.make
@@ -568,6 +568,7 @@ crc32_test$(EXEEXT): \
 currency_test$(EXEEXT): \
   $(common_test_objects) \
   currency_test.o \
+  timer.o \
 
 expression_template_0_test$(EXEEXT): \
   $(common_test_objects) \



reply via email to

[Prev in Thread] Current Thread [Next in Thread]