[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;
- [lmi-commits] [lmi] odd/eraseme_error updated (69d06e9 -> 58863bf), Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error 35f8824 1/9: Trace IRR calculations, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error 7b5c07f 6/9: Move and rename a function, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error 6c0d108 4/9: Add a couple obvious tests, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error 95690a5 5/9: Remove a confusing overload, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error cf5cced 7/9: Re-break; fail better, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error 273f15b 8/9: Restore un-breakage, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error 58863bf 9/9: Improve speed measurements,
Greg Chicares <=
- [lmi-commits] [lmi] odd/eraseme_error 05e74a5 3/9: Clean up, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error ee0dc1c 2/9: Fix the problem in a slapdash manner, Greg Chicares, 2021/07/08