lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master b1eecea 02/14: Stabilize unit-test timing


From: Greg Chicares
Subject: [lmi-commits] [lmi] master b1eecea 02/14: Stabilize unit-test timing
Date: Mon, 5 Apr 2021 18:26:45 -0400 (EDT)

branch: master
commit b1eeceab9bfe48847c15982529a9f760711eb582
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Stabilize unit-test timing
    
    The operations measured in 'mete_*' functions run too quickly for stable
    measurements. Inserted a loop into each one, to make it run a hundred
    times. Incidentally assigned scalar results to 'volatile' variables, to
    prevent the loop from being optimized away.
---
 commutation_functions_test.cpp | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/commutation_functions_test.cpp b/commutation_functions_test.cpp
index b56e480..77ebea7 100644
--- a/commutation_functions_test.cpp
+++ b/commutation_functions_test.cpp
@@ -59,7 +59,10 @@ void mete_olcf
     ,std::vector<double> const& i
     )
 {
-    OLCommFns(q, i);
+    for(int j = 0; j < 100; ++j)
+        {
+        volatile auto z = OLCommFns(q, i);
+        }
 }
 
 void mete_ulcf
@@ -68,7 +71,10 @@ void mete_ulcf
     ,std::vector<double> const& ig
     )
 {
-    ULCommFns(q, ic, ig, mce_option1_for_7702, mce_monthly);
+    for(int j = 0; j < 100; ++j)
+        {
+        volatile auto z = ULCommFns(q, ic, ig, mce_option1_for_7702, 
mce_monthly);
+        }
 }
 
 void mete_reserve
@@ -76,9 +82,12 @@ void mete_reserve
     ,std::vector<double>& reserve
     )
 {
-    double premium = (10.0 * ulcf.aDomega() + ulcf.kM()[0]) / ulcf.aN()[0];
-    assign(reserve, premium * ulcf.aD() - ulcf.kC());
-    assign(reserve, fwd_sum(reserve) / ulcf.EaD());
+    for(int j = 0; j < 100; ++j)
+        {
+        volatile double premium = (10.0 * ulcf.aDomega() + ulcf.kM()[0]) / 
ulcf.aN()[0];
+        assign(reserve, premium * ulcf.aD() - ulcf.kC());
+        assign(reserve, fwd_sum(reserve) / ulcf.EaD());
+        }
 }
 
 /// Exactly reproduce Table 2 from Eckley's paper.



reply via email to

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