[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/002 c80d1eb 09/14: Add two experimental opti
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/002 c80d1eb 09/14: Add two experimental options |
Date: |
Thu, 17 Sep 2020 16:27:15 -0400 (EDT) |
branch: valyuta/002
commit c80d1eb01527255b2d61f17180a4e5e8d7193be7
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Add two experimental options
#define MAKE_IT_FASTER
Reimplement currency::round() so that it just returns its argument.
#define MAKE_IT_EVEN_FASTER
Reimplement from_double() and to_double() so that they just return
their arguments.
One might suppose that a twenty-first century optimizing compiler would
generate about the same code in both these cases. But...not! Compare the
'--selftest' timings in this and the next few commits:
$cd /opt/lmi/bin
$file ./lmi_cli_shared.exe
./lmi_cli_shared.exe: PE32 executable (console) Intel 80386, for MS W...
$wine ./lmi_cli_shared.exe --accept --data_path=/opt/lmi/data --selftest
Test speed:
naic, no solve : 1.022e-01 s mean; 101411 us least of 10 runs
naic, specamt solve : 1.857e-01 s mean; 177872 us least of 6 runs
naic, ee prem solve : 1.631e-01 s mean; 161682 us least of 7 runs
finra, no solve : 2.660e-02 s mean; 26228 us least of 38 runs
finra, specamt solve: 9.539e-02 s mean; 94189 us least of 11 runs
finra, ee prem solve: 8.767e-02 s mean; 86780 us least of 12 runs
---
currency.hpp | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/currency.hpp b/currency.hpp
index fa83e7a..11738f5 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -40,6 +40,11 @@
# error No can do!
#endif // !defined CURRENCY_UNIT_IS_CENTS && defined
CURRENCY_HAS_INTEGER_DATATYPE
+// Similar restrictions apply to these macros, but they'd be tedious
+// to write. Use them only with floating-point dollars.
+//#define MAKE_IT_FASTER
+//#define MAKE_IT_EVEN_FASTER
+
#if !defined CURRENCY_HAS_INTEGER_DATATYPE
# if defined __GNUC__
# pragma GCC diagnostic push
@@ -139,8 +144,13 @@ class currency
// data_type from_double(double d) const {return
static_cast<data_type>(100.000000000001 * d);}
// ...less bad:
// data_type from_double(double d) const {return
bourn_cast<data_type>(round(cents_per_dollar * d));}
+#if !defined MAKE_IT_EVEN_FASTER
data_type from_double(double d) const {return round(cents_per_dollar * d);}
double to_double() const {return bourn_cast<double>(m_) /
cents_per_dollar;}
+#else // defined MAKE_IT_EVEN_FASTER
+ data_type from_double(double d) const {return d;}
+ double to_double() const {return m_;}
+#endif // defined MAKE_IT_EVEN_FASTER
// data_type from_double(double d) const {return
static_cast<data_type>(cents_per_dollar * d);}
// double to_double() const {return static_cast<double>(m_) /
cents_per_dollar;}
#if 0 // will a fwd decl be wanted somewhere?
@@ -152,7 +162,12 @@ class currency
#else // 1
data_type round(double d) const
{
+#if !defined MAKE_IT_FASTER
return bourn_cast<data_type>(std::round(d));
+#else // defined MAKE_IT_FASTER
+ static_assert(std::is_floating_point<data_type>::value);
+ return d;
+#endif // defined MAKE_IT_FASTER
}
#endif // 1
data_type m_ = {0};
- [lmi-commits] [lmi] valyuta/002 updated (9433c8e -> 3f71218), Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 53de040 01/14: Add an extra argument to currency(data_type), Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 c5e0b01 04/14: Make currency class mandatory, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 c80d1eb 09/14: Add two experimental options,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/002 e4cb0f1 10/14: Make it float, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 cfe336c 11/14: Make it faster, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 4a6bc6c 02/14: Resolve confusion, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 0d47d8d 03/14: Refine an assertion, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 27c198e 05/14: fixup, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 3d1ff11 06/14: Remove useless casts, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 594bd68 07/14: Allow floating currency::data_type, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 1fbef51 13/14: Make it even faster, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 420fac7 08/14: Allow currency to be dollars rather than cents, Greg Chicares, 2020/09/17
- [lmi-commits] [lmi] valyuta/002 3f71218 14/14: Trivially avoid spurious regression errors, Greg Chicares, 2020/09/17