[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 951a9c9 1/8: Improve IRR speed measurements
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 951a9c9 1/8: Improve IRR speed measurements |
Date: |
Fri, 9 Jul 2021 01:41:16 -0400 (EDT) |
branch: master
commit 951a9c96b4d5093b32068ff922067de2cb1057df
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Improve IRR speed measurements
Running tests ten times improves measurement stability.
For the container form actually used in production:
i686-w64-mingw32 4.571e-02 s mean; 45293 us least of 22 runs
x86_64-pc-linux-gnu 2.347e-02 s mean; 23426 us least of 43 runs
---
financial_test.cpp | 71 +++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 52 insertions(+), 19 deletions(-)
diff --git a/financial_test.cpp b/financial_test.cpp
index 0a5630d..263d768 100644
--- a/financial_test.cpp
+++ b/financial_test.cpp
@@ -24,16 +24,60 @@
#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>
+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};
@@ -211,24 +255,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] master updated (55873f1 -> ce8b814), Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master 485d642 4/8: Augment unit tests, Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master be56aad 2/8: Move and rename a present-value function, Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master 873c574 6/8: Expunge an unneeded overload, Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master ac0da7b 3/8: Use a more appropriate unit-test macro, Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master 951a9c9 1/8: Improve IRR speed measurements,
Greg Chicares <=
- [lmi-commits] [lmi] master 81ede74 5/8: Reimplement fv(), Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master ce8b814 8/8: Record speed measurements, Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master 7c21f2a 7/8: Optionally trace IRR iterations, Greg Chicares, 2021/07/09