lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] valyuta/005 4483b09 1/9: Avoid passing 'currency' by


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/005 4483b09 1/9: Avoid passing 'currency' by const reference
Date: Wed, 20 Jan 2021 00:51:31 -0500 (EST)

branch: valyuta/005
commit 4483b09a9bf445c58b1be677221a72fbde4de13f
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Avoid passing 'currency' by const reference
    
    See:
      https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-in
    sizeof(currency) equals sizeof(double), so pass by value.
    
    This change would appear to make both 32- and 64-bit msw builds slightly
    slower, so is the guideline appropriate for currency operators?
---
 Speed_gcc_i686-w64-mingw32    | 12 ++++++------
 Speed_gcc_x86_64-pc-linux-gnu | 12 ++++++------
 Speed_gcc_x86_64-w64-mingw32  | 12 ++++++------
 currency.hpp                  | 34 +++++++++++++++++-----------------
 round_to.hpp                  |  4 ++--
 5 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/Speed_gcc_i686-w64-mingw32 b/Speed_gcc_i686-w64-mingw32
index 2d520be..1a9bf4c 100644
--- a/Speed_gcc_i686-w64-mingw32
+++ b/Speed_gcc_i686-w64-mingw32
@@ -1,7 +1,7 @@
 Test speed:
-  naic, no solve      : 5.330e-02 s mean;      52985 us least of  19 runs
-  naic, specamt solve : 9.927e-02 s mean;      98880 us least of  11 runs
-  naic, ee prem solve : 9.033e-02 s mean;      89979 us least of  12 runs
-  finra, no solve     : 1.740e-02 s mean;      16380 us least of  58 runs
-  finra, specamt solve: 5.878e-02 s mean;      57988 us least of  18 runs
-  finra, ee prem solve: 5.415e-02 s mean;      53516 us least of  19 runs
+  naic, no solve      : 5.456e-02 s mean;      53445 us least of  19 runs
+  naic, specamt solve : 1.045e-01 s mean;      99974 us least of  10 runs
+  naic, ee prem solve : 9.203e-02 s mean;      90746 us least of  11 runs
+  finra, no solve     : 1.682e-02 s mean;      16372 us least of  60 runs
+  finra, specamt solve: 6.793e-02 s mean;      59843 us least of  15 runs
+  finra, ee prem solve: 5.659e-02 s mean;      54196 us least of  18 runs
diff --git a/Speed_gcc_x86_64-pc-linux-gnu b/Speed_gcc_x86_64-pc-linux-gnu
index 129aff9..8d93344 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.051e-02 s mean;      20208 us least of  49 runs
-  naic, specamt solve : 3.693e-02 s mean;      36525 us least of  28 runs
-  naic, ee prem solve : 3.364e-02 s mean;      33349 us least of  30 runs
-  finra, no solve     : 5.936e-03 s mean;       5791 us least of 100 runs
-  finra, specamt solve: 2.091e-02 s mean;      20439 us least of  48 runs
-  finra, ee prem solve: 1.935e-02 s mean;      18944 us least of  52 runs
+  naic, no solve      : 2.098e-02 s mean;      20150 us least of  48 runs
+  naic, specamt solve : 3.686e-02 s mean;      36555 us least of  28 runs
+  naic, ee prem solve : 3.372e-02 s mean;      33271 us least of  30 runs
+  finra, no solve     : 5.899e-03 s mean;       5760 us least of 100 runs
+  finra, specamt solve: 2.090e-02 s mean;      20547 us least of  48 runs
+  finra, ee prem solve: 1.930e-02 s mean;      18972 us least of  52 runs
diff --git a/Speed_gcc_x86_64-w64-mingw32 b/Speed_gcc_x86_64-w64-mingw32
index 947a781..0e1ef2e 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.756e-02 s mean;      27296 us least of  37 runs
-  naic, specamt solve : 4.712e-02 s mean;      46713 us least of  22 runs
-  naic, ee prem solve : 4.321e-02 s mean;      42860 us least of  24 runs
-  finra, no solve     : 1.049e-02 s mean;      10287 us least of  96 runs
-  finra, specamt solve: 2.817e-02 s mean;      27897 us least of  36 runs
-  finra, ee prem solve: 2.626e-02 s mean;      26013 us least of  39 runs
+  naic, no solve      : 3.128e-02 s mean;      27432 us least of  32 runs
+  naic, specamt solve : 4.865e-02 s mean;      47049 us least of  21 runs
+  naic, ee prem solve : 4.766e-02 s mean;      43150 us least of  22 runs
+  finra, no solve     : 1.130e-02 s mean;      10306 us least of  89 runs
+  finra, specamt solve: 3.318e-02 s mean;      28502 us least of  31 runs
+  finra, ee prem solve: 2.663e-02 s mean;      26056 us least of  38 runs
diff --git a/currency.hpp b/currency.hpp
index bdd5c4b..9b1856f 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -54,8 +54,8 @@ class LMI_SO currency
     currency() = default;
     explicit currency(data_type z, raw_cents) : m_ {z} {}
 
-    currency& operator+=(currency const& z) {m_ += z.m_; return *this;}
-    currency& operator-=(currency const& z) {m_ -= z.m_; return *this;}
+    currency& operator+=(currency z) {m_ += z.m_; return *this;}
+    currency& operator-=(currency z) {m_ -= z.m_; return *this;}
 
     currency& operator*=(int             z) {m_ *= z   ; return *this;}
 
@@ -67,40 +67,40 @@ class LMI_SO currency
     data_type m_ = {};
 };
 
-inline bool operator==(currency const& lhs, currency const& rhs)
+inline bool operator==(currency lhs, currency rhs)
     {return lhs.cents() == rhs.cents();}
-inline bool operator< (currency const& lhs, currency const& rhs)
+inline bool operator< (currency lhs, currency rhs)
     {return lhs.cents() <  rhs.cents();}
-inline bool operator!=(currency const& lhs, currency const& rhs)
+inline bool operator!=(currency lhs, currency rhs)
     {return !operator==(lhs, rhs);}
-inline bool operator> (currency const& lhs, currency const& rhs)
+inline bool operator> (currency lhs, currency rhs)
     {return  operator< (rhs, lhs);}
-inline bool operator<=(currency const& lhs, currency const& rhs)
+inline bool operator<=(currency lhs, currency rhs)
     {return !operator> (lhs, rhs);}
-inline bool operator>=(currency const& lhs, currency const& rhs)
+inline bool operator>=(currency lhs, currency rhs)
     {return !operator< (lhs, rhs);}
 
-inline currency operator-(currency const& z)
+inline currency operator-(currency z)
     {return currency(-z.cents(), raw_cents {});}
 
-inline currency operator+(currency const& lhs, currency const& rhs)
+inline currency operator+(currency lhs, currency rhs)
     {return currency {lhs} += rhs;}
-inline currency operator-(currency const& lhs, currency const& rhs)
+inline currency operator-(currency lhs, currency rhs)
     {return currency {lhs} -= rhs;}
 
-inline currency operator*(currency const& lhs, int rhs)
+inline currency operator*(currency lhs, int rhs)
     {return currency {lhs} *= rhs;}
-inline currency operator*(int lhs, currency const& rhs)
+inline currency operator*(int lhs, currency rhs)
     {return currency {rhs} *= lhs;}
 
-inline double operator*(currency const& lhs, double rhs)
+inline double operator*(currency lhs, double rhs)
     {return lhs.d() * rhs;}
-inline double operator*(double lhs, currency const& rhs)
+inline double operator*(double lhs, currency rhs)
     {return lhs * rhs.d();}
-inline double operator/(currency const& lhs, double rhs)
+inline double operator/(currency lhs, double rhs)
     {return lhs.d() / rhs;}
 
-inline std::ostream& operator<<(std::ostream& os, currency const& z)
+inline std::ostream& operator<<(std::ostream& os, currency z)
     {return os << z.d();}
 
 inline std::vector<double> doubleize(std::vector<currency> const& z)
diff --git a/round_to.hpp b/round_to.hpp
index 2b88dd0..132c077 100644
--- a/round_to.hpp
+++ b/round_to.hpp
@@ -270,7 +270,7 @@ class round_to
     currency c(RealType r) const;
     std::vector<currency> c(std::vector<RealType> const& r) const;
 
-    currency c(currency const& z) const;
+    currency c(currency z) const;
 
     int decimals() const;
     rounding_style style() const;
@@ -404,7 +404,7 @@ inline std::vector<currency> round_to<RealType>::c
 
 // !! need unit tests
 template<typename RealType>
-inline currency round_to<RealType>::c(currency const& z) const
+inline currency round_to<RealType>::c(currency z) const
 {
 #if defined CURRENCY_UNIT_IS_CENTS
     return (decimals_ < currency::cents_digits) ? c(z.d()) : z;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]