From bf1eac02dd0e17e7001568ac055811c7f224b69d Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 3 Jan 2024 22:48:49 +0100 Subject: [PATCH] Scheduler-test: binary search over continuous domain - textbook implementation - capture results from visited points - average results form the last three points to damp statistic fluctuations --- tests/vault/gear/stress-test-rig.hpp | 103 +++++++++++++++++++++++++-- wiki/thinkPad.ichthyo.mm | 53 +++++++++++++- 2 files changed, 148 insertions(+), 8 deletions(-) diff --git a/tests/vault/gear/stress-test-rig.hpp b/tests/vault/gear/stress-test-rig.hpp index b1573bd31..dc693ecc5 100644 --- a/tests/vault/gear/stress-test-rig.hpp +++ b/tests/vault/gear/stress-test-rig.hpp @@ -81,6 +81,7 @@ #include "vault/gear/scheduler.hpp" #include "lib/time/timevalue.hpp" //#include "lib/iter-explorer.hpp" +#include "lib/meta/function.hpp" #include "lib/format-string.hpp" #include "lib/format-cout.hpp"//////////////////////////TODO RLY? //#include "lib/util.hpp" @@ -99,8 +100,8 @@ namespace gear { namespace test { using util::_Fmt; -// using util::min; -// using util::max; + using util::min; + using util::max; // using util::isnil; // using util::limited; // using util::unConst; @@ -115,7 +116,7 @@ namespace test { // using std::string; // using std::function; -// using std::make_pair; + using std::make_pair; using std::make_tuple; // using std::forward; // using std::string; @@ -130,6 +131,71 @@ namespace test { namespace stress_test_rig { + template + struct _ValidateBinarySearchFun + { + static_assert (not sizeof(P), "Functor unsuitable for binary search. " + "Expected signature pair(PAR)" ); + }; + template + struct _ValidateBinarySearchFun(PAR), PAR> + { + using Result = RES; + }; + template + inline auto + make_binarySearchResults() + { + using Sig = typename lib::meta::_Fun::Sig; + using Res = typename _ValidateBinarySearchFun::Result; + using Data = std::vector>; + return Data{}; + } + + template + inline auto + binarySearch_impl (FUN&& fun, CON results, PAR lower, PAR upper, PAR epsilon) + { + REQUIRE (lower <= upper); + while ((upper-lower) >= epsilon) + { + PAR div = (upper-lower) / 2; + results.emplace_back (fun(div)); + bool hit = results.back().first; + if (hit) + upper = div; + else + lower = div; + } + return results; + } + + template + inline auto + binarySearch_inner (FUN&& fun, PAR lower, PAR upper, PAR epsilon) + { + auto results = make_binarySearchResults(); + return binarySearch_impl(forward (fun), results, lower,upper,epsilon); + } + + template + inline auto + binarySearch_upper (FUN&& fun, PAR lower, PAR upper, PAR epsilon) + { + REQUIRE (lower <= upper); + auto results = make_binarySearchResults(); + results.emplace_back (fun(upper)); + bool hit = results.back().first; + if (not hit) + {// the upper end breaks contract => search above + PAR len = (upper-lower); + lower = upper - len/10; + upper = lower + 14*len/10; + } + return binarySearch_impl(forward (fun), results, lower,upper,epsilon); + } + + /** * Specific stress test scheme to determine the * »breaking point« where the Scheduler starts to slip @@ -207,7 +273,30 @@ namespace test { Res conductBinarySearch (FUN&& runTestCase) { - UNIMPLEMENTED ("invoke a library implementation of binary search"); + auto results = binarySearch_upper (forward (runTestCase), 0.0, CONF::UPPER_STRESS, CONF::EPSILON); + uint s = results.size(); + ENSURE (s >= 2); + Res res; + auto& [sf,pf,sdev,avgD,avgT,expT] = res; + // average data over the last three steps investigated for smoothing + uint points = min (results.size(), 3u); + for (uint i=results.size()-points; i - - + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ Mittelpunkt auswerten: test(m) +

+ + +
+ + + + +
+ + + + + + + + + + + + + +