lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master ff1dd28 1/7: Improve measurement of compound-


From: Greg Chicares
Subject: [lmi-commits] [lmi] master ff1dd28 1/7: Improve measurement of compound-interest performance
Date: Wed, 7 Oct 2020 19:36:13 -0400 (EDT)

branch: master
commit ff1dd28691ccde769cc1299483a7e8fe85811d4c
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Improve measurement of compound-interest performance
    
    A calculation like
      expm1(log1p(i) * n)
    is so fast that a single iteration may take less than the microsecond
    resolution reported--see the zero-μs timings reported here:
      https://lists.nongnu.org/archive/html/lmi/2020-10/msg00027.html
    Changed the functions that are measured to run a hundred thousand
    iterations instead of one.
    
    Incidentally removed a superfluous static_cast.
---
 math_functions_test.cpp | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index 3baa6aa..b44d4aa 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -200,10 +200,13 @@ void mete0()
 {
     double volatile x;
     stifle_warning_for_unused_value(x);
-    x = i_upper_12_over_12_from_i_naive<double>()(0.04);
-    x = i_from_i_upper_12_over_12_naive<double>()(0.04);
-    x = d_upper_12_from_i_naive        <double>()(0.04);
-    x = net_i_from_gross_naive<double,365>()(0.04, 0.007, 0.003);
+    for(int j = 0; j < 100000; ++j)
+        {
+        x = i_upper_12_over_12_from_i_naive<double>()(0.04);
+        x = i_from_i_upper_12_over_12_naive<double>()(0.04);
+        x = d_upper_12_from_i_naive        <double>()(0.04);
+        x = net_i_from_gross_naive<double,365>()(0.04, 0.007, 0.003);
+        }
 }
 
 // This implementation uses production functors.
@@ -211,24 +214,33 @@ void mete1()
 {
     double volatile x;
     stifle_warning_for_unused_value(x);
-    x = i_upper_12_over_12_from_i<double>()(0.04);
-    x = i_from_i_upper_12_over_12<double>()(0.04);
-    x = d_upper_12_from_i        <double>()(0.04);
-    x = net_i_from_gross<double,365>()(0.04, 0.007, 0.003);
+    for(int j = 0; j < 100000; ++j)
+        {
+        x = i_upper_12_over_12_from_i<double>()(0.04);
+        x = i_from_i_upper_12_over_12<double>()(0.04);
+        x = d_upper_12_from_i        <double>()(0.04);
+        x = net_i_from_gross<double,365>()(0.04, 0.007, 0.003);
+        }
 }
 
 void mete2()
 {
     double volatile x;
     stifle_warning_for_unused_value(x);
-    x = i_upper_n_over_n_from_i_T<double,365>()(0.01);
+    for(int j = 0; j < 100000; ++j)
+        {
+        x = i_upper_n_over_n_from_i_T<double,365>()(0.01);
+        }
 }
 
 void mete3()
 {
-    double volatile x;
+    long double volatile x;
     stifle_warning_for_unused_value(x);
-    x = static_cast<double>(i_upper_n_over_n_from_i_T<long 
double,365>()(0.01));
+    for(int j = 0; j < 100000; ++j)
+        {
+        x = i_upper_n_over_n_from_i_T<long double,365>()(0.01);
+        }
 }
 
 void assay_speed()



reply via email to

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