lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] odd/eraseme_error 58863bf 9/9: Improve speed measure


From: Greg Chicares
Subject: [lmi-commits] [lmi] odd/eraseme_error 58863bf 9/9: Improve speed measurements
Date: Thu, 8 Jul 2021 16:26:48 -0400 (EDT)

branch: odd/eraseme_error
commit 58863bf0527cee9a7b5d833656c24aac5c7cba71
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Improve speed measurements
---
 financial_test.cpp | 71 +++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 52 insertions(+), 19 deletions(-)

diff --git a/financial_test.cpp b/financial_test.cpp
index b32f361..578e9e4 100644
--- a/financial_test.cpp
+++ b/financial_test.cpp
@@ -24,13 +24,12 @@
 #include "financial.hpp"
 
 #include "materially_equal.hpp"
+#include "miscellany.hpp"               // stifle_warning_for_unused_value()
 #include "ssize_lmi.hpp"
 #include "test_tools.hpp"
 #include "timer.hpp"
 
 #include <cmath>                        // fabs()
-#include <functional>                   // bind()
-#include <iomanip>                      // Formatting of optional detail.
 #include <iostream>
 #include <vector>
 
@@ -64,6 +63,51 @@ long double pv
     return z;
 }
 
+void mete_0
+    (std::vector<double> const& payments
+    ,std::vector<double> const& benefits
+    )
+{
+    constexpr int decimals {5};
+    static std::vector<double> results(payments.size());
+    volatile double unoptimizable;
+    stifle_warning_for_unused_value(unoptimizable);
+    for(int i = 0; i < 10; ++i)
+        {
+        irr
+            (payments.begin()
+            ,payments.end()
+            ,benefits.begin()
+            ,results.begin()
+            ,decimals
+            );
+        unoptimizable = results.front();
+        }
+}
+
+void mete_1
+    (std::vector<double> const& payments
+    ,std::vector<double> const& benefits
+    )
+{
+    constexpr int decimals {5};
+    static std::vector<double> results(payments.size());
+    volatile double unoptimizable;
+    stifle_warning_for_unused_value(unoptimizable);
+    for(int i = 0; i < 10; ++i)
+        {
+        irr
+            (payments
+            ,benefits
+            ,results
+            ,payments.size()
+            ,payments.size()
+            ,decimals
+            );
+        unoptimizable = results.front();
+        }
+}
+
 int test_main(int, char*[])
 {
     double pmts[3] = {100.0,  200.0,  300.0};
@@ -254,24 +298,13 @@ int test_main(int, char*[])
         <= tolerance
         );
 
-    typedef std::vector<double>::iterator VI;
+    auto f0 = [&p, &b] {mete_0(p, b);};
+    auto f1 = [&p, &b] {mete_1(p, b);};
     std::cout
-        << "  Speed test: vector of irrs, length "
-        << p.size()
-        << ", "
-        << decimals
-        << " decimals\n    "
-        << TimeAnAliquot
-            (std::bind
-                (irr<VI,VI,VI>
-                ,p.begin()
-                ,p.end()
-                ,b.begin()
-                ,results.begin()
-                ,decimals
-                )
-            )
-        << '\n'
+        << "\n  Speed tests..."
+        << "\n  iterator  form: " << TimeAnAliquot(f0)
+        << "\n  container form: " << TimeAnAliquot(f1)
+        << std::endl
         ;
 
     return 0;



reply via email to

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