[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/005 6767160 08/10: Temporarily don't use cen
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/005 6767160 08/10: Temporarily don't use cents |
Date: |
Thu, 21 Jan 2021 17:48:16 -0500 (EST) |
branch: valyuta/005
commit 6767160d9dae140138e72fb331ad45b51eae901e
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Temporarily don't use cents
This code path is a transitional aid that will never be released into
production (so it doesn't much matter that the unit-test workarounds
are kludges). There are two major differences between this branch and
master:
(1) multiplying and dividing by 100 on conversion between currency and
floating point; and
(2) rounding all currency amounts to whole cents;
and this path demonstrates the cost of (1), which, for solve-heavy
scenarios, is
- about ten percent for msw (both 32- and 64-bit), and
- about sixteen percent for pc-linux-gnu x86_64.
It makes sense that the penalty is greater for pc-linux-gnu, which is
always faster than msw under 'wine'. It is conjectured that much of the
extra work in (1) could be eliminated by careful line-by-line revisions.
---
Speed_gcc_i686-w64-mingw32 | 12 ++++++------
Speed_gcc_x86_64-pc-linux-gnu | 12 ++++++------
Speed_gcc_x86_64-w64-mingw32 | 12 ++++++------
currency.hpp | 11 ++++++++++-
currency_test.cpp | 5 +++++
loads_test.cpp | 4 ++++
round_to_test.cpp | 5 +++++
7 files changed, 42 insertions(+), 19 deletions(-)
diff --git a/Speed_gcc_i686-w64-mingw32 b/Speed_gcc_i686-w64-mingw32
index 879f80b..a5fe19f 100644
--- a/Speed_gcc_i686-w64-mingw32
+++ b/Speed_gcc_i686-w64-mingw32
@@ -1,7 +1,7 @@
Test speed:
- naic, no solve : 5.379e-02 s mean; 53446 us least of 19 runs
- naic, specamt solve : 1.001e-01 s mean; 99577 us least of 10 runs
- naic, ee prem solve : 9.113e-02 s mean; 90771 us least of 11 runs
- finra, no solve : 1.657e-02 s mean; 16402 us least of 61 runs
- finra, specamt solve: 5.885e-02 s mean; 58558 us least of 17 runs
- finra, ee prem solve: 5.412e-02 s mean; 53919 us least of 19 runs
+ naic, no solve : 4.831e-02 s mean; 48156 us least of 21 runs
+ naic, specamt solve : 9.056e-02 s mean; 90364 us least of 12 runs
+ naic, ee prem solve : 8.270e-02 s mean; 82552 us least of 13 runs
+ finra, no solve : 1.618e-02 s mean; 15743 us least of 62 runs
+ finra, specamt solve: 5.652e-02 s mean; 54358 us least of 18 runs
+ finra, ee prem solve: 5.036e-02 s mean; 50200 us least of 20 runs
diff --git a/Speed_gcc_x86_64-pc-linux-gnu b/Speed_gcc_x86_64-pc-linux-gnu
index a4432b6..0493db3 100644
--- a/Speed_gcc_x86_64-pc-linux-gnu
+++ b/Speed_gcc_x86_64-pc-linux-gnu
@@ -1,7 +1,7 @@
Test speed:
- naic, no solve : 2.039e-02 s mean; 20072 us least of 50 runs
- naic, specamt solve : 3.704e-02 s mean; 36518 us least of 27 runs
- naic, ee prem solve : 3.374e-02 s mean; 33142 us least of 30 runs
- finra, no solve : 5.961e-03 s mean; 5834 us least of 100 runs
- finra, specamt solve: 2.107e-02 s mean; 20472 us least of 48 runs
- finra, ee prem solve: 1.947e-02 s mean; 19032 us least of 52 runs
+ naic, no solve : 1.734e-02 s mean; 16554 us least of 58 runs
+ naic, specamt solve : 3.106e-02 s mean; 30265 us least of 33 runs
+ naic, ee prem solve : 2.827e-02 s mean; 27783 us least of 36 runs
+ finra, no solve : 5.503e-03 s mean; 5201 us least of 100 runs
+ finra, specamt solve: 1.845e-02 s mean; 18055 us least of 55 runs
+ finra, ee prem solve: 1.700e-02 s mean; 16579 us least of 59 runs
diff --git a/Speed_gcc_x86_64-w64-mingw32 b/Speed_gcc_x86_64-w64-mingw32
index 7f2b2d3..f970c0a 100644
--- a/Speed_gcc_x86_64-w64-mingw32
+++ b/Speed_gcc_x86_64-w64-mingw32
@@ -1,7 +1,7 @@
Test speed:
- naic, no solve : 2.780e-02 s mean; 27428 us least of 36 runs
- naic, specamt solve : 4.750e-02 s mean; 46912 us least of 22 runs
- naic, ee prem solve : 4.361e-02 s mean; 43042 us least of 23 runs
- finra, no solve : 1.057e-02 s mean; 10328 us least of 95 runs
- finra, specamt solve: 2.841e-02 s mean; 28041 us least of 36 runs
- finra, ee prem solve: 2.641e-02 s mean; 26042 us least of 38 runs
+ naic, no solve : 2.483e-02 s mean; 24523 us least of 41 runs
+ naic, specamt solve : 4.254e-02 s mean; 42068 us least of 24 runs
+ naic, ee prem solve : 3.906e-02 s mean; 38668 us least of 26 runs
+ finra, no solve : 1.013e-02 s mean; 9900 us least of 99 runs
+ finra, specamt solve: 2.728e-02 s mean; 26028 us least of 37 runs
+ finra, ee prem solve: 2.456e-02 s mean; 24206 us least of 41 runs
diff --git a/currency.hpp b/currency.hpp
index a87a9a3..2784c81 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -51,7 +51,7 @@ inline std::vector<double> dblize(std::vector<currency>
const& z)
#else // defined USE_CURRENCY_CLASS
-# define CURRENCY_UNIT_IS_CENTS
+//# define CURRENCY_UNIT_IS_CENTS
class raw_cents {}; // Tag class.
@@ -131,8 +131,17 @@ inline std::ostream& operator<<(std::ostream& os, currency
z)
inline currency from_cents(double z)
{
+# if defined CURRENCY_UNIT_IS_CENTS
if(z != std::rint(z)) throw std::runtime_error("Nonintegral cents.");
return currency(z, raw_cents{});
+# else // !defined CURRENCY_UNIT_IS_CENTS
+ // If currency unit is dollars rather than cents, then:
+ // - dividing by 100 is the only reasonable thing to do here, even
+ // though 'cents_per_dollar' is unity; and
+ // - a value such as $.01 cannot be integral, so the desired
+ // invariant that the result is integral must be sacrificed.
+ return currency(z / 100.0, raw_cents{});
+# endif // !defined CURRENCY_UNIT_IS_CENTS
}
inline double dblize(currency z) {return z.d();}
diff --git a/currency_test.cpp b/currency_test.cpp
index 897534b..c715500 100644
--- a/currency_test.cpp
+++ b/currency_test.cpp
@@ -63,6 +63,10 @@ void currency_test::test()
test_copy_ctor();
test_explicit_ctor();
test_negation();
+// CURRENCY !! Most of these tests assume that the currency unit is
+// cents. It's not worth adapting them to any other case because
+// soon this macro will, in effect, always be defined.
+#if defined CURRENCY_UNIT_IS_CENTS
test_plus_or_minus_eq();
test_plus_or_minus();
test_times_int();
@@ -74,6 +78,7 @@ void currency_test::test()
test_round_double();
test_round_currency();
test_quodlibet();
+#endif // defined CURRENCY_UNIT_IS_CENTS
}
void currency_test::test_default_ctor()
diff --git a/loads_test.cpp b/loads_test.cpp
index 11a0249..3fa44ed 100644
--- a/loads_test.cpp
+++ b/loads_test.cpp
@@ -159,7 +159,11 @@ void LoadsTest::TestCalculations(char const* file, int
line)
INVOKE_BOOST_TEST(materially_equal(0.500000,
loads_.refundable_sales_load_proportion()[0]), file, line);
// (8.00 + 5.25 + 0.50) / 2 = 13.75 / 2 = 6.875, rounded to cents
+# if defined CURRENCY_UNIT_IS_CENTS
INVOKE_BOOST_TEST(from_cents(688) == loads_.monthly_policy_fee
(mce_gen_mdpt)[0] , file, line);
+# else // !defined CURRENCY_UNIT_IS_CENTS
+ INVOKE_BOOST_TEST(materially_equal(6.88, dblize(loads_.monthly_policy_fee
(mce_gen_mdpt)[0])), file, line);
+# endif // !defined CURRENCY_UNIT_IS_CENTS
INVOKE_BOOST_TEST(from_cents(150) == loads_.annual_policy_fee
(mce_gen_mdpt)[0] , file, line);
INVOKE_BOOST_TEST(materially_equal(0.000625, loads_.specified_amount_load
(mce_gen_mdpt)[0]), file, line);
// 12 bp and 19 bp, both converted to monthly, then added together.
diff --git a/round_to_test.cpp b/round_to_test.cpp
index 9813dfc..e438d37 100644
--- a/round_to_test.cpp
+++ b/round_to_test.cpp
@@ -580,7 +580,12 @@ void round_to_test::test_fundamentals()
// Test rounding double to currency.
currency c = round0.c(1.61803398875);
BOOST_TEST((1.62 - dblize(c)) < 1e-14);
+# if defined CURRENCY_UNIT_IS_CENTS
BOOST_TEST_EQUAL(162, c.cents());
+# else // !defined CURRENCY_UNIT_IS_CENTS
+ // Arguably this isn't quite meaningful:
+ BOOST_TEST_EQUAL(1.62, c.cents());
+# endif // !defined CURRENCY_UNIT_IS_CENTS
// c *= 0.61803398875;
// BOOST_TEST_EQUAL(1, c);
- [lmi-commits] [lmi] valyuta/005 updated (133d646 -> 9e42155), Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 d763c34 04/10: Clean up, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 2712277 02/10: Default class currency's special member functions, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 86cba7f 09/10: Temporarily don't use currency class, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 7f6a453 01/10: Revert "Partially revert the last commit", Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 c0a93cf 03/10: Reorder currency unit tests, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 e40980b 05/10: Optionally detect nonintegral cents at run time, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 61396fd 06/10: Expunge the unclean macro just added, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 4b0bf87 07/10: Detect nonintegral cents along every path, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 6767160 08/10: Temporarily don't use cents,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/005 9e42155 10/10: Undo temporary changes: use currency class with cents, Greg Chicares, 2021/01/21