Library/Application: switch Microbenchmark + SyncBarrier tests
...these were already written envisionaging he new API, so it's more or less a drop-in replacement. - cant use vector anymore, since thread objects are move-only - use ScopedCollection instead, which also has the benefit of allocating the requires space up-front. Allow to deduce the type parameter of the placed elements
This commit is contained in:
parent
6cd16a61a6
commit
ff052ec5a2
6 changed files with 22 additions and 29 deletions
|
|
@ -309,7 +309,7 @@ namespace lib {
|
|||
* push new entry at the end of this container
|
||||
* and build object of type TY in place there
|
||||
*/
|
||||
template<class TY, typename...ARGS>
|
||||
template<class TY =I, typename...ARGS>
|
||||
TY&
|
||||
emplace (ARGS&& ...args)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -55,12 +55,11 @@
|
|||
|
||||
|
||||
#include "lib/meta/function.hpp"
|
||||
//#include "vault/thread-wrapper.hpp" /////////////////////////////////////////////OOO wieder ThreadJoinable verwenden
|
||||
#include "lib/sync-barrier.hpp" ///TODO
|
||||
#include <thread> ///TODO
|
||||
#include "lib/scoped-collection.hpp"
|
||||
#include "lib/sync-barrier.hpp"
|
||||
#include "lib/thread.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
||||
|
|
@ -161,20 +160,18 @@ namespace test{
|
|||
ASSERT_VALID_SIGNATURE (decltype(subject), size_t(size_t));
|
||||
|
||||
struct Thread
|
||||
// : ThreadJoinable
|
||||
: std::thread
|
||||
: lib::ThreadJoinable<>
|
||||
{
|
||||
Thread(FUN const& testSubject, size_t loopCnt, SyncBarrier& testStart)
|
||||
// : ThreadJoinable("Micro-Benchmark" ///////////////////////////////////////////////////////////OOO wieder Lumiera Thread-Wrapper verwenden #1279
|
||||
: std::thread(
|
||||
[=, &testStart]() // local copy of the test-subject-Functor
|
||||
: ThreadJoinable{"Micro-Benchmark"
|
||||
,[=, &testStart]() // local copy of the test-subject-Functor
|
||||
{
|
||||
testStart.sync(); // block until all threads are ready
|
||||
auto start = system_clock::now();
|
||||
for (size_t i=0; i < loopCnt; ++i)
|
||||
checksum += testSubject(i);
|
||||
duration = system_clock::now () - start;
|
||||
})
|
||||
}}
|
||||
{ }
|
||||
// Note: barrier at begin and join at end both ensure data synchronisation
|
||||
Dur duration{}; // measured time within thread
|
||||
|
|
@ -182,10 +179,9 @@ namespace test{
|
|||
};
|
||||
|
||||
SyncBarrier testStart{nThreads + 1}; // coordinated start of timing measurement
|
||||
std::vector<Thread> threads;
|
||||
threads.reserve(nThreads);
|
||||
lib::ScopedCollection<Thread> threads(nThreads);
|
||||
for (size_t n=0; n<nThreads; ++n) // create test threads
|
||||
threads.emplace_back (subject, repeatCnt, testStart);
|
||||
threads.emplace (subject, repeatCnt, testStart);
|
||||
|
||||
testStart.sync(); // barrier until all threads are ready
|
||||
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ namespace test {
|
|||
double time_sleepWait_4 = performanceTest<MonitorSync, 4>();
|
||||
double time_sleepWait_2 = performanceTest<MonitorSync, 2>();
|
||||
|
||||
cout<<"\n___Microbenchmark_______"
|
||||
cout<<"\n___Microbenchmark_______ (µs)"
|
||||
<<"\nemptySetup : "<<time_emptySetup
|
||||
<<"\n : "
|
||||
<<"\nSyncBarrier (2 Thr) : "<<time_yieldWait_2
|
||||
|
|
@ -179,7 +179,7 @@ namespace test {
|
|||
<<"\nMonitorWait (4 Thr) : "<<time_sleepWait_4
|
||||
<<"\nMonitorWait (8 Thr) : "<<time_sleepWait_8
|
||||
<<"\nMonitorWait (16 Thr) : "<<time_sleepWait_16
|
||||
<<"\n_____________________\n"
|
||||
<<"\n________________________\n"
|
||||
<<"\nbarriers..... "<<NUM_STAGES
|
||||
<<endl;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,15 +28,13 @@
|
|||
#include "lib/test/run.hpp"
|
||||
#include "lib/sync-barrier.hpp"
|
||||
#include "lib/iter-explorer.hpp"
|
||||
#include "lib/util-foreach.hpp"
|
||||
#include "lib/thread.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <array>
|
||||
|
||||
using test::Test;
|
||||
using util::and_all;
|
||||
using lib::explore;
|
||||
using std::array;
|
||||
|
||||
|
|
@ -66,11 +64,12 @@ namespace test {
|
|||
* - book in the compound sum plus a further random number
|
||||
*/
|
||||
class TestThread
|
||||
: std::thread ////////////////////////////////////////////////////////////////////OOO TOD-oh
|
||||
: public lib::Thread
|
||||
{
|
||||
public:
|
||||
TestThread()
|
||||
: thread{[&]()
|
||||
: Thread{"Load Test"
|
||||
,[&]()
|
||||
{ //-STAGE-1------------------------------
|
||||
localSum = rand() % 1000; // generate local value
|
||||
stage1.fetch_add (localSum); // book in local value
|
||||
|
|
@ -83,12 +82,10 @@ namespace test {
|
|||
afterThread.sync(); // wait for other threads and supervisor
|
||||
|
||||
finish.fetch_add(1); // mark completion of this thread
|
||||
thread::detach(); //////////////////////////////////////////////OOO Wech-oh
|
||||
}}
|
||||
{ }
|
||||
|
||||
uint localSum; // *deliberately* not initialised to avoid race
|
||||
bool isRunning() const { return thread::joinable(); } ///////////////////////OOO Wack-oh
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -123,7 +120,7 @@ namespace test {
|
|||
array<TestThread,NUM_THREADS> threads;
|
||||
|
||||
CHECK (0 == finish);
|
||||
CHECK (and_all (threads, [](auto& t){ return t.isRunning(); }));
|
||||
CHECK (explore(threads).and_all());
|
||||
|
||||
afterThread.sync();
|
||||
sleep_for (5ms); // give the threads a chance to terminate
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ namespace test{
|
|||
{
|
||||
uint x = rand() % 1000;
|
||||
globalSum += (i + x);
|
||||
threads.emplace<TestThread> (&TestThread::doIt, i, x);
|
||||
threads.emplace (&TestThread::doIt, i, x);
|
||||
} // Note: bind to member function, copying arguments
|
||||
|
||||
while (explore(threads).has_any())
|
||||
|
|
|
|||
|
|
@ -80549,7 +80549,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="flag-yellow"/>
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node CREATED="1696029414385" ID="ID_140265798" MODIFIED="1696029417676" TEXT="weitere Tests...">
|
||||
<node COLOR="#338800" CREATED="1696029465122" ID="ID_1060376805" MODIFIED="1696180242543" TEXT="SessionCommandFunction_test">
|
||||
<node COLOR="#338800" CREATED="1696029465122" FOLDED="true" ID="ID_1060376805" MODIFIED="1696180242543" TEXT="SessionCommandFunction_test">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node CREATED="1696036153400" ID="ID_1572079642" MODIFIED="1696036156883" TEXT="Umstellung">
|
||||
<node CREATED="1696036158076" ID="ID_429764463" MODIFIED="1696036170175" TEXT="puh... der Test ist komplex">
|
||||
|
|
@ -80880,12 +80880,12 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<node COLOR="#338800" CREATED="1696029465122" ID="ID_1515483274" MODIFIED="1696357491529" TEXT="SubsystemRunner_test">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1696030280182" ID="ID_244374373" MODIFIED="1696366309566" TEXT="SyncBarrier_test + Microbenchmark">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node CREATED="1696029465124" ID="ID_1556068052" MODIFIED="1696029514685" TEXT="typed-counter-test.cpp (/zLumi/tests/basics)"/>
|
||||
<node CREATED="1696029465120" ID="ID_1705540772" MODIFIED="1696029510893" TEXT="call-queue-test.cpp (/zLumi/tests/basics)"/>
|
||||
<node CREATED="1696029465120" ID="ID_1782746519" MODIFIED="1696029465120" TEXT="bus-term-test.cpp (/zLumi/tests/stage)"/>
|
||||
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1696030280182" ID="ID_244374373" MODIFIED="1696030328243" TEXT="SyncBarrier_test">
|
||||
<icon BUILTIN="flag-pink"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1696029465119" ID="ID_820648476" MODIFIED="1696029572456" TEXT="eigentliche Verwendungen">
|
||||
<node CREATED="1696029465121" ID="ID_1756135675" MODIFIED="1696029465121" TEXT="diagnostic-context-test.cpp (/zLumi/tests/basics)"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue