[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 2a3d961 03/13: Measure cost of a needless tra
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 2a3d961 03/13: Measure cost of a needless transcendental calculation |
Date: |
Fri, 9 Apr 2021 18:42:36 -0400 (EDT) |
branch: master
commit 2a3d961046af842d4373db60535c7c2d7812893d
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Measure cost of a needless transcendental calculation
---
math_functions_test.cpp | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index 1267823..d42b268 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -26,6 +26,7 @@
#include "fenv_lmi.hpp"
#include "materially_equal.hpp"
#include "miscellany.hpp" // stifle_warning_for_unused_value()
+#include "stl_extensions.hpp" // nonstd::power()
#include "test_tools.hpp"
#include "timer.hpp"
@@ -191,7 +192,7 @@ void sample_results()
fenv_initialize();
}
-// These 'meteN' functions perform the same set of operations using
+// These 'mete[0123]' functions perform the same set of operations using
// different implementations.
// This implementation naively uses std::pow(); it is both slower and
@@ -243,6 +244,37 @@ void mete3()
}
}
+// These 'mete[45]' functions calculate 10^-9 in different ways.
+// The SGI extension is about eight times as fast as calling a
+// transcendental function; that outcome is not surprising, but
+// quantifying it is useful. Of course, it would not be surprising
+// to find that a table lookup would be even faster for "reasonable"
+// powers of ten.
+
+void mete4()
+{
+ double volatile base = 10.0;
+ int volatile exp = 9;
+ double volatile x;
+ stifle_warning_for_unused_value(x);
+ for(int j = 0; j < 100000; ++j)
+ {
+ x = 1.0 / nonstd::power(base, exp);
+ }
+}
+
+void mete5()
+{
+ double volatile base = 10.0;
+ int volatile exp = -9;
+ double volatile x;
+ stifle_warning_for_unused_value(x);
+ for(int j = 0; j < 100000; ++j)
+ {
+ x = std::pow(base, exp);
+ }
+}
+
void assay_speed()
{
std::cout << "Speed tests:\n";
@@ -250,6 +282,8 @@ void assay_speed()
std::cout << " std::expm1 " << TimeAnAliquot(mete1) << '\n';
std::cout << " double i365 " << TimeAnAliquot(mete2) << '\n';
std::cout << " long double i365 " << TimeAnAliquot(mete3) << '\n';
+ std::cout << " 10^-9 nonstd " << TimeAnAliquot(mete4) << '\n';
+ std::cout << " 10^-9 std " << TimeAnAliquot(mete5) << '\n';
}
int test_main(int, char*[])
- [lmi-commits] [lmi] master updated (8aa09b9 -> a32cee0), Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 79741b1 01/13: Assert a precondition more consistently, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 358c5c9 06/13: Modernize, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master edb098f 02/13: Strengthen unit tests, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 2a3d961 03/13: Measure cost of a needless transcendental calculation,
Greg Chicares <=
- [lmi-commits] [lmi] master 6bc828a 05/13: Realign, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 290dc89 10/13: Remove a source of inaccuracy [285], Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master a32cee0 13/13: Hoist a division, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 1e49ee3 04/13: Revise 'round_to' documentation [286], Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 1bead9e 08/13: Purge unwanted, commented-out code, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master ce9ed5c 07/13: Add an inchoate test of power-of-ten scaling, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master 858d037 09/13: Include appropriate headers, and say why they're included, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master ca63009 11/13: Expunge an obsolete comment, Greg Chicares, 2021/04/09
- [lmi-commits] [lmi] master c41faec 12/13: Resolve a marked defect [284], Greg Chicares, 2021/04/09