[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 09c4f0c: Augment a unit test; reformat its ou
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 09c4f0c: Augment a unit test; reformat its output |
Date: |
Tue, 6 Oct 2020 10:13:50 -0400 (EDT) |
branch: master
commit 09c4f0c3ba2a03f724a1deda00d6e9ab1c3fac70
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Augment a unit test; reformat its output
Reformatted output of {expm1, log1p} vs. pow results, to make it easier
to compare accuracy. For x87 (i686 only), the {expm1, log1p} results
differ only in the seventeenth (in)significant digit for double vs.
extended precision, so extended precision offers no material advantage
here--as expected, because the technique involves only a few floating-
point instructions.
Added tests comparing speed of {expm1, log1p} to pow for long double vs.
double arguments. For both i686-w64-mingw32 and x86_64-w64-mingw32, pow
is slightly slower, and of course far less accurate. However, for
x86_64-pc-linux-gnu, {expm1, log1p} runs three and a half times faster
than pow; and the {expm1, log1p} technique runs two and a half times
faster for double than for long double arguments.
Thus, it's okay to change from long double to double arguments and from
extended to double precision, though there's no benefit with MingW-w64;
but for x86_64-pc-linux-gnu, double arguments work much faster than long
double, without sacrificing accuracy (and extended precision is at best
discouraged for x86_64 anyway).
See the concurrent discussion on the mailing list.
Raw data: i686-w64-mingw32-gcc-8.3-win32
Speed tests:
std::pow 1.463e-06 s mean; 1 us least of 6836 runs
std::expm1 1.239e-06 s mean; 1 us least of 8073 runs
double i365 7.609e-07 s mean; 1 us least of 13144 runs
long double i365 7.520e-07 s mean; 1 us least of 13299 runs
Daily rate corresponding to 1% annual interest, by various methods:
000000000111111111122
123456789012345678901
0.0000272615520089941669031 method in production
0.0000272615520089941669031 long double precision, std::expm1 and...
0.0000272615520089941739887 long double precision, std::pow
0.0000272615520089941672124 double precision, std::expm1 and std:...
0.0000272615520089392049385 double precision, std::pow
x86_64-w64-mingw32-gcc-8.3 raw data:
Speed tests:
std::pow 1.602e-06 s mean; 2 us least of 6245 runs
std::expm1 1.304e-06 s mean; 1 us least of 7667 runs
double i365 7.516e-07 s mean; 1 us least of 13306 runs
long double i365 7.630e-07 s mean; 1 us least of 13108 runs
Daily rate corresponding to 1% annual interest, by various methods:
000000000111111111122
123456789012345678901
0.0000272615520089941669031 method in production
0.0000272615520089941672124 double precision, std::expm1 and std:...
0.0000272615520089392049385 double precision, std::pow
pc-linux-gnu gcc-9 raw data:
Speed tests:
std::pow 4.565e-06 s mean; 2 us least of 2191 runs
std::expm1 8.252e-07 s mean; 0 us least of 12119 runs
double i365 7.233e-08 s mean; 0 us least of 138246 runs
long double i365 1.721e-07 s mean; 0 us least of 58098 runs
Daily rate corresponding to 1% annual interest, by various methods:
000000000111111111122
123456789012345678901
0.0000272615520089941669014 method in production
0.0000272615520089941672124 double precision, std::expm1 and std:...
0.0000272615520089392049385 double precision, std::pow
---
math_functions_test.cpp | 47 +++++++++++++++++++++++++++++++++--------------
1 file changed, 33 insertions(+), 14 deletions(-)
diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index a03868a..3baa6aa 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -162,28 +162,30 @@ void sample_results()
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
std::cout.precision(25);
std::cout
- << "\n daily rate corresponding to 1% annual interest"
- << ", by various methods\n"
- << " method in production\n "
- << i_upper_n_over_n_from_i <long double,365>()(0.01) << '\n'
+ << "\nDaily rate corresponding to 1% annual interest"
+ << ", by various methods:\n"
+ << " 000000000111111111122\n"
+ << " 123456789012345678901\n"
+ << " " << i_upper_n_over_n_from_i <long double,365>()(0.01)
+ << " method in production\n"
;
#if defined LMI_X87
fenv_precision(fe_ldblprec);
std::cout
- << " long double precision, std::expm1 and std::log1p\n "
- << i_upper_n_over_n_from_i_T <long double,365>()(0.01) << '\n'
- << " long double precision, std::pow\n "
- << i_upper_n_over_n_from_i_naive<long double,365>()(0.01) << '\n'
+ << " " << i_upper_n_over_n_from_i_T <long double,365>()(0.01)
+ << " long double precision, std::expm1 and std::log1p\n"
+ << " " << i_upper_n_over_n_from_i_naive<long double,365>()(0.01)
+ << " long double precision, std::pow\n"
;
fenv_initialize();
fenv_precision(fe_dblprec);
#endif // defined LMI_X87
std::cout
- << " double precision, std::expm1 and std::log1p\n "
- << i_upper_n_over_n_from_i_T <double,365>()(0.01) << '\n'
- << " double precision, std::pow\n "
- << i_upper_n_over_n_from_i_naive<double,365>()(0.01) << '\n'
+ << " " << i_upper_n_over_n_from_i_T <double,365>()(0.01)
+ << " double precision, std::expm1 and std::log1p\n"
+ << " " << i_upper_n_over_n_from_i_naive<double,365>()(0.01)
+ << " double precision, std::pow\n"
;
fenv_initialize();
@@ -215,10 +217,27 @@ void mete1()
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);
+}
+
+void mete3()
+{
+ 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));
+}
+
void assay_speed()
{
- std::cout << " Speed test: std::pow \n " << TimeAnAliquot(mete0) <<
'\n';
- std::cout << " Speed test: std::expm1\n " << TimeAnAliquot(mete1) <<
'\n';
+ std::cout << "Speed tests:\n";
+ std::cout << " std::pow " << TimeAnAliquot(mete0) << '\n';
+ std::cout << " std::expm1 " << TimeAnAliquot(mete1) << '\n';
+ std::cout << " double i365 " << TimeAnAliquot(mete2) << '\n';
+ std::cout << " long double i365 " << TimeAnAliquot(mete3) << '\n';
}
int test_main(int, char*[])
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [lmi] master 09c4f0c: Augment a unit test; reformat its output,
Greg Chicares <=