[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 041ca2fb 5/5: Add a measurement
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 041ca2fb 5/5: Add a measurement |
Date: |
Wed, 18 May 2022 15:54:20 -0400 (EDT) |
branch: master
commit 041ca2fb1e5074069664d56abab4b377efe9e9ae
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Add a measurement
Production uses a template with a parameter of some floating-point type,
so show results for both 'double' and 'long double' types. Incidentally
improved output formatting.
This is important because all pc-linux-gnu and msw system_test '.test'
files differ, due mainly or perhaps entirely to monthly interest rates.
If such discrepancies can be removed, then either test is as accurate
as the other, and the timings:
44.382 x86_64-w64-mingw32
13.146 x86_64-pc-linux-gnu
suggest which one is more practical to run many times per commit during
development.
The output for both architectures is copied here because it is
interesting in more than one way:
- all of the "Daily rate" calculations match except only those labelled
"double precision, production template"
- glibc's pow() is much slower, and its expm1() much faster, so the
library routines used by MinGW-w64 must differ greatly
x86_64, sse, gcc, posix
Speed tests:
std::pow 2.189e-01 s mean; 214245 us least of 5 runs
std::expm1 2.059e-02 s mean; 20151 us least of 49 runs
double i365 2.790e-03 s mean; 2729 us least of 100 runs
long double i365 1.421e-02 s mean; 13897 us least of 71 runs
10^-9 nonstd 4.634e-04 s mean; 438 us least of 100 runs
10^-9 std 2.180e-03 s mean; 2127 us least of 100 runs
Daily rate corresponding to 1% annual interest, by various methods:
000000000111111111122
123456789012345678901
0.00327373978219886392598 long double prec, production template
0.00327373978219886392598 long double prec, std::expm1 and std::log1p
0.00327373978219886395923 long double prec, std::pow
0.00327373978219886374239 double prec, production template
0.00327373978219886330870 double prec, std::expm1 and std::log1p
0.00327373978219891448305 double prec, std::pow
x86_64, sse, gcc, msw
Speed tests:
std::pow 6.926e-02 s mean; 67563 us least of 15 runs
std::expm1 4.424e-02 s mean; 43520 us least of 23 runs
double i365 6.839e-03 s mean; 6735 us least of 100 runs
long double i365 7.930e-03 s mean; 7771 us least of 100 runs
10^-9 nonstd 4.520e-04 s mean; 438 us least of 100 runs
10^-9 std 2.402e-03 s mean; 2255 us least of 100 runs
Daily rate corresponding to 1% annual interest, by various methods:
000000000111111111122
123456789012345678901
0.00327373978219886392598 long double prec, production template
0.00327373978219886392598 long double prec, std::expm1 and std::log1p
0.00327373978219886395923 long double prec, std::pow
0.00327373978219886417607 double prec, production template
0.00327373978219886330870 double prec, std::expm1 and std::log1p
0.00327373978219891448305 double prec, std::pow
---
math_functions_test.cpp | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index ec5862af..c2795f1e 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -167,31 +167,33 @@ void sample_results()
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
std::cout.precision(23);
std::cout
- << "\nDaily rate corresponding to 1% annual interest"
+ << "Daily rate corresponding to 1% annual interest"
<< ", by various methods:\n"
<< " 000000000111111111122\n"
<< " 123456789012345678901\n"
<< " " << i_upper_n_over_n_from_i <long double,12>()(intrate)
- << " method in production\n"
+ << " long double prec, production template\n"
;
#if defined LMI_X87
fenv_precision(fe_ldblprec);
#endif // defined LMI_X87
std::cout
<< " " << i_upper_n_over_n_from_i_T <long double,12>()(intrate)
- << " long double precision, std::expm1 and std::log1p\n"
+ << " long double prec, std::expm1 and std::log1p\n"
<< " " << i_upper_n_over_n_from_i_naive<long double,12>()(intrate)
- << " long double precision, std::pow\n"
+ << " long double prec, std::pow\n"
;
#if defined LMI_X87
fenv_initialize();
fenv_precision(fe_dblprec);
#endif // defined LMI_X87
std::cout
+ << " " << i_upper_n_over_n_from_i <double,12>()(intrate)
+ << " double prec, production template\n"
<< " " << i_upper_n_over_n_from_i_T <double,12>()(intrate)
- << " double precision, std::expm1 and std::log1p\n"
+ << " double prec, std::expm1 and std::log1p\n"
<< " " << i_upper_n_over_n_from_i_naive<double,12>()(intrate)
- << " double precision, std::pow\n"
+ << " double prec, std::pow\n"
;
fenv_initialize();
@@ -294,6 +296,7 @@ void assay_speed()
std::cout << " long double i365 " << TimeAnAliquot(mete3) << '\n';
std::cout << " 10^-9 nonstd " << TimeAnAliquot(mete4) << '\n';
std::cout << " 10^-9 std " << TimeAnAliquot(mete5) << '\n';
+ std::cout << std::endl;
}
template<typename T>
@@ -557,6 +560,8 @@ int test_main(int, char*[])
)
);
+ std::cout << LMI_CONTEXT << '\n' << std::endl;
+
assay_speed();
sample_results();