TEST_F(SignalTest, MultiEmit){ cout << "Instantiating signal object" << endl; Signal<int, int> testSignal; BasicTimer bt; BasicTimer bt2; cout << "Connecting signal" << endl; bt.start(); int id = testSignal.connectSlot(ExecutorScheme::STRAND, staticSumFunction); bt.stop(); cout << "Time to connect: " << bt.getElapsedMilliseconds() << "ms" << endl; cout << "Emitting signal" << endl; bt.start(); list<thread> threads; const uint32_t nThreads = 64; std::atomic<uint32_t> threadsRemaining{nThreads}; for (uint32_t i=0; i<nThreads; i++){ threads.emplace_back([&, i](){ for (uint32_t i=0; i<1000000; ++i){ testSignal.emitSignal(1, 2); } uint32_t tr = threadsRemaining.fetch_sub(1); cout << "Threads remaining: " << tr-1 << endl; cout << "globalStaticInt: " << globalStaticIntX << endl; }); } bt.stop(); bt2.start(); while (bt2.getElapsedSeconds() < 60.0) { if (globalStaticIntX == 1000000*3*nThreads) { bt2.stop(); break; } std::this_thread::sleep_for(std::chrono::milliseconds(100)); } //ASSERT_LT(bt2.getElapsedSeconds(), 0.1); cout << "Time to emit: " << bt.getElapsedMilliseconds() << "ms" << endl; cout << "Time to emit and process: " << bt2.getElapsedMilliseconds() << "ms" << endl; cout << "Net time to process: " << bt2.getElapsedMilliseconds() - bt.getElapsedMilliseconds() << "ms" << endl; ASSERT_EQ(0, id); testSignal.disconnectAllSlots(); for (auto &t : threads) t.join(); }
TEST_F(SignalTest, StrandSignal) { cout << "Instantiating signal object" << endl; Signal<int, int> testSignal; BasicTimer bt; BasicTimer bt2; cout << "Connecting signal" << endl; bt.start(); int id = testSignal.connectSlot(ExecutorScheme::STRAND, staticSumFunction); bt.stop(); cout << "Time to connect: " << bt.getElapsedMilliseconds() << "ms" << endl; cout << "Emitting signal" << endl; bt.start(); bt2.start(); testSignal.emitSignal(1, 2); bt.stop(); while (bt2.getElapsedSeconds() < 0.1) { if (globalStaticIntX == 3) { bt2.stop(); break; } } ASSERT_LT(bt2.getElapsedSeconds(), 0.1); ASSERT_EQ(globalStaticIntX, 3); cout << "Time to emit: " << bt.getElapsedMilliseconds() << "ms" << endl; cout << "Time to emit and process: " << bt2.getElapsedMilliseconds() << "ms" << endl; cout << "Net time to process: " << bt2.getElapsedMilliseconds() - bt.getElapsedMilliseconds() << "ms" << endl; ASSERT_EQ(0, id); testSignal.disconnectAllSlots(); }