lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] valyuta/004 54e71c7 2/2: Cache all use of class prod


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/004 54e71c7 2/2: Cache all use of class product_data
Date: Sun, 20 Dec 2020 20:38:29 -0500 (EST)

branch: valyuta/004
commit 54e71c75155572258eb852729407abec1e199b4a
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Cache all use of class product_data
    
    The speed improvement is remarkable. Compared to measurements recorded
    20200829T2153 ccb70ce5ad6378), 'master' takes about 25% less time:
      100% -  5408 /  7562 = 28.5% // x86_64-pc-linux-gnu
      100% - 15350 / 20707 = 25.9% // i686-w64-mingw32
    
    and compared to measurements of 20201120T1444Z (commit c7fc77b7577b7),
    'valyuta/004' is faster than historical 'master' for scenarios that
    don't perform solves, though slower for those that do:
    
    x86_64-pc-linux-gnu
      naic, ee prem solve 30324 formerly, now 38466
      finra, no solve      7562 formerly, now 6240
    
    x86_64-w64-mingw32
      naic, ee prem solve 38911 formerly, now 45212
      finra, no solve     14756 formerly, now 10600
    
    i686-w64-mingw32
      naic, ee prem solve 84836 formerly, now 97594
      finra, no solve     21725 formerly, now 17199
---
 Speed_gcc_i686-w64-mingw32    | 12 ++++++------
 Speed_gcc_x86_64-pc-linux-gnu | 12 ++++++------
 Speed_gcc_x86_64-w64-mingw32  | 12 ++++++------
 antediluvian_stubs.cpp        |  8 ++++++++
 basic_values.hpp              |  4 ++--
 database.cpp                  |  4 +++-
 ihs_basicval.cpp              |  8 ++++++--
 product_data.cpp              |  6 +++++-
 product_data.hpp              |  4 ++--
 verify_products.cpp           |  5 +++--
 10 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/Speed_gcc_i686-w64-mingw32 b/Speed_gcc_i686-w64-mingw32
index ed848c4..c7e4093 100644
--- a/Speed_gcc_i686-w64-mingw32
+++ b/Speed_gcc_i686-w64-mingw32
@@ -1,7 +1,7 @@
 Test speed:
-  naic, no solve      : 6.312e-02 s mean;      62955 us least of  16 runs
-  naic, specamt solve : 1.125e-01 s mean;     112235 us least of   9 runs
-  naic, ee prem solve : 1.029e-01 s mean;     102592 us least of  10 runs
-  finra, no solve     : 2.212e-02 s mean;      22020 us least of  46 runs
-  finra, specamt solve: 6.689e-02 s mean;      66783 us least of  15 runs
-  finra, ee prem solve: 6.196e-02 s mean;      61856 us least of  17 runs
+  naic, no solve      : 5.829e-02 s mean;      58099 us least of  18 runs
+  naic, specamt solve : 1.076e-01 s mean;     107301 us least of  10 runs
+  naic, ee prem solve : 9.776e-02 s mean;      97594 us least of  11 runs
+  finra, no solve     : 1.733e-02 s mean;      17199 us least of  58 runs
+  finra, specamt solve: 6.469e-02 s mean;      61764 us least of  16 runs
+  finra, ee prem solve: 5.712e-02 s mean;      56948 us least of  18 runs
diff --git a/Speed_gcc_x86_64-pc-linux-gnu b/Speed_gcc_x86_64-pc-linux-gnu
index f2aa254..9ed9940 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.537e-02 s mean;      25079 us least of  40 runs
-  naic, specamt solve : 4.433e-02 s mean;      43847 us least of  23 runs
-  naic, ee prem solve : 4.046e-02 s mean;      40133 us least of  25 runs
-  finra, no solve     : 8.051e-03 s mean;       7811 us least of 100 runs
-  finra, specamt solve: 2.506e-02 s mean;      24752 us least of  40 runs
-  finra, ee prem solve: 2.327e-02 s mean;      22794 us least of  43 runs
+  naic, no solve      : 2.471e-02 s mean;      23555 us least of  41 runs
+  naic, specamt solve : 4.276e-02 s mean;      42035 us least of  24 runs
+  naic, ee prem solve : 3.894e-02 s mean;      38466 us least of  26 runs
+  finra, no solve     : 6.447e-03 s mean;       6240 us least of 100 runs
+  finra, specamt solve: 2.347e-02 s mean;      23063 us least of  43 runs
+  finra, ee prem solve: 2.161e-02 s mean;      21346 us least of  47 runs
diff --git a/Speed_gcc_x86_64-w64-mingw32 b/Speed_gcc_x86_64-w64-mingw32
index bc404b5..25c4644 100644
--- a/Speed_gcc_x86_64-w64-mingw32
+++ b/Speed_gcc_x86_64-w64-mingw32
@@ -1,7 +1,7 @@
 Test speed:
-  naic, no solve      : 3.303e-02 s mean;      32901 us least of  31 runs
-  naic, specamt solve : 5.357e-02 s mean;      53426 us least of  19 runs
-  naic, ee prem solve : 4.942e-02 s mean;      49285 us least of  21 runs
-  finra, no solve     : 1.466e-02 s mean;      14540 us least of  69 runs
-  finra, specamt solve: 3.315e-02 s mean;      33030 us least of  31 runs
-  finra, ee prem solve: 3.109e-02 s mean;      30975 us least of  33 runs
+  naic, no solve      : 2.894e-02 s mean;      28834 us least of  35 runs
+  naic, specamt solve : 4.942e-02 s mean;      49167 us least of  21 runs
+  naic, ee prem solve : 4.534e-02 s mean;      45212 us least of  23 runs
+  finra, no solve     : 1.072e-02 s mean;      10600 us least of  94 runs
+  finra, specamt solve: 2.921e-02 s mean;      29075 us least of  35 runs
+  finra, ee prem solve: 2.714e-02 s mean;      27009 us least of  37 runs
diff --git a/antediluvian_stubs.cpp b/antediluvian_stubs.cpp
index 236d0c1..b15968c 100644
--- a/antediluvian_stubs.cpp
+++ b/antediluvian_stubs.cpp
@@ -134,10 +134,18 @@ product_data::product_data(std::string const&)
 
 product_data::~product_data() = default;
 
+product_data::product_data(fs::path const&)
+{}
+
 product_data::product_data(product_data const&)
     :MemberSymbolTable <product_data> {}
 {}
 
+std::string product_data::actual_filename(std::string const&)
+{
+    return empty_string;
+}
+
 int product_data::class_version() const
 {
     return 0;
diff --git a/basic_values.hpp b/basic_values.hpp
index aeda9b7..95bfd9f 100644
--- a/basic_values.hpp
+++ b/basic_values.hpp
@@ -119,7 +119,7 @@ class LMI_SO BasicValues
     double                InvestmentManagementFee()    const;
 
     yare_input                          yare_input_;
-    product_data     const              product_;
+    std::shared_ptr<product_data>       product_;
     product_database const              database_;
     std::shared_ptr<lingo>              lingo_;
     std::shared_ptr<FundData>           FundData_;
@@ -134,7 +134,7 @@ class LMI_SO BasicValues
     std::shared_ptr<Irc7702>            Irc7702_;
     std::shared_ptr<Irc7702A>           Irc7702A_;
 
-    product_data     const& product () const {return product_;}
+    product_data     const& product () const {return *product_;}
     product_database const& database() const {return database_;}
 
     currency GetAnnualTgtPrem(int a_year, currency a_specamt) const;
diff --git a/database.cpp b/database.cpp
index 11d5896..52e519b 100644
--- a/database.cpp
+++ b/database.cpp
@@ -192,7 +192,9 @@ void product_database::initialize(std::string const& 
product_name)
         }
     else
         {
-        product_data const p(product_name);
+//      product_data const p(product_name);
+        std::string f = product_data::actual_filename(product_name);
+        product_data const& p(*product_data::read_via_cache(f));
         std::string const filename(p.datum("DatabaseFilename"));
         LMI_ASSERT(!filename.empty());
         db_ = DBDictionary::read_via_cache(AddDataDir(filename));
diff --git a/ihs_basicval.cpp b/ihs_basicval.cpp
index cb0e06c..0132ab0 100644
--- a/ihs_basicval.cpp
+++ b/ihs_basicval.cpp
@@ -68,7 +68,9 @@ BasicValues::BasicValues(Input const& input)
 //  ,product_            (yare_input_.ProductName)
 // Safe to dereference?
 //  ,product_            
(*product_data::read_via_cache(yare_input_.ProductName))
-    ,product_            
(*product_data::read_via_cache(product_data::actual_filename(yare_input_.ProductName)))
+//  ,product_            
(*product_data::read_via_cache(product_data::actual_filename(yare_input_.ProductName)))
+    // Throw if null?
+    ,product_            
(product_data::read_via_cache(product_data::actual_filename(yare_input_.ProductName)))
     ,database_           (yare_input_)
     ,DefnLifeIns_        {mce_cvat}
     ,DefnMaterialChange_ {mce_unnecessary_premium}
@@ -101,7 +103,9 @@ BasicValues::BasicValues
     :yare_input_         (Input{})
 //  ,product_            (a_ProductName)
 // Safe to dereference?
-    ,product_            
(*product_data::read_via_cache(product_data::actual_filename(a_ProductName)))
+//  ,product_            
(*product_data::read_via_cache(product_data::actual_filename(a_ProductName)))
+    // Throw if null?
+    ,product_            
(product_data::read_via_cache(product_data::actual_filename(a_ProductName)))
     ,database_
         (a_ProductName
         ,a_Gender
diff --git a/product_data.cpp b/product_data.cpp
index 2496786..3d396ce 100644
--- a/product_data.cpp
+++ b/product_data.cpp
@@ -26,7 +26,7 @@
 
 #include "alert.hpp"
 #include "assert_lmi.hpp"
-#include "ce_product_name.hpp"
+////#include "ce_product_name.hpp"
 #include "contains.hpp"
 #include "data_directory.hpp"           // AddDataDir()
 #include "map_lookup.hpp"
@@ -148,10 +148,14 @@ product_data::product_data(std::string const& 
product_name)
 {
 }
 
+#if 0
+// Either add 'ce_product_name.o' to unit-test targets in makefiles,
+// or abandon this idea.
 product_data::product_data(ce_product_name const& product_name)
     :product_data(fs::path(actual_filename(product_name.str())))
 {
 }
+#endif // 0
 
 product_data::product_data(product_data const& z)
 // Is this initializer-list necessary?
diff --git a/product_data.hpp b/product_data.hpp
index d64d1cd..a734c08 100644
--- a/product_data.hpp
+++ b/product_data.hpp
@@ -33,7 +33,7 @@
 
 #include <string>
 
-class LMI_SO_FWD_DECL ce_product_name;
+////class LMI_SO_FWD_DECL ce_product_name;
 
 /// A single product datum: a string with an optional gloss.
 ///
@@ -95,7 +95,7 @@ class LMI_SO product_data
   public:
     explicit product_data(fs::path const& filename);
     explicit product_data(std::string const& product_name);
-    explicit product_data(ce_product_name const& product_name);
+////    explicit product_data(ce_product_name const& product_name);
     ~product_data() override;
 
     std::string const& datum(std::string const& name) const;
diff --git a/verify_products.cpp b/verify_products.cpp
index 1e1f44b..ff97a74 100644
--- a/verify_products.cpp
+++ b/verify_products.cpp
@@ -55,7 +55,7 @@ class product_verifier
     std::string      const product_name_;
     std::string      const gender_str_  ;
     std::string      const smoking_str_ ;
-    product_data     const p_           ;
+    product_data     const& p_           ; // or just std::shared_ptr?
     mcenum_gender    const gender_      ;
     mcenum_smoking   const smoking_     ;
     product_database const db0_         ;
@@ -77,7 +77,8 @@ product_verifier::product_verifier
     :product_name_ {product_name}
     ,gender_str_   {gender_str}
     ,smoking_str_  {smoking_str}
-    ,p_            (product_name)
+//  ,p_            (product_name)
+    ,p_            
(*product_data::read_via_cache(product_data::actual_filename(product_name)))
     ,gender_       {mce_gender (gender_str ).value()}
     ,smoking_      {mce_smoking(smoking_str).value()}
     ,db0_



reply via email to

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