[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()
- [lmi-commits] [lmi] master updated (61f5559 -> 14d582d), Greg Chicares, 2020/10/07
- [lmi-commits] [lmi] master ff1dd28 1/7: Improve measurement of compound-interest performance,
Greg Chicares <=
- [lmi-commits] [lmi] master 7846a21 2/7: Fix defect introduced 20201004T1606Z: typo in variable name, Greg Chicares, 2020/10/07
- [lmi-commits] [lmi] master b8061ca 3/7: Treat gcc versions "10" and "10.0" as the same, Greg Chicares, 2020/10/07
- [lmi-commits] [lmi] master 9a6cab4 4/7: Treat gcc versions "[89]" and "[89]\.*" as the same, Greg Chicares, 2020/10/07
- [lmi-commits] [lmi] master 81e3462 5/7: Specify a default data directory for CGI, Greg Chicares, 2020/10/07
- [lmi-commits] [lmi] master 14d582d 7/7: Trap exceptions from filesystem library, Greg Chicares, 2020/10/07
- [lmi-commits] [lmi] master c85b44f 6/7: Force print directory more sensibly, Greg Chicares, 2020/10/07