| 306 | } |
| 307 | |
| 308 | void runParallel(size_t threadsCount, int64_t durationSeconds, DispatchFunction run) { |
| 309 | if (threadsCount > 1) { |
| 310 | std::vector<Ref<Thread>> threads; |
| 311 | std::atomic_bool cont = true; |
| 312 | |
| 313 | for (size_t i = 0; i < 8; i++) { |
| 314 | auto thread = Thread::create(STRING_LITERAL("Worker Thread"), ThreadQoSClassMax, [&]() { |
| 315 | while (cont) { |
| 316 | run(); |
| 317 | } |
| 318 | }); |
| 319 | |
| 320 | SC_ASSERT(thread); |
| 321 | |
| 322 | threads.emplace_back(thread.value()); |
| 323 | } |
| 324 | |
| 325 | std::this_thread::sleep_for(std::chrono::seconds(durationSeconds)); |
| 326 | |
| 327 | cont = false; |
| 328 | |
| 329 | for (const auto& thread : threads) { |
| 330 | thread->join(); |
| 331 | } |
| 332 | } else { |
| 333 | snap::utils::time::StopWatch sw; |
| 334 | sw.start(); |
| 335 | |
| 336 | while (sw.elapsedSeconds() < durationSeconds) { |
| 337 | run(); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | bool runTypeScriptTests(std::string_view modulePath, |
| 343 | Valdi::IJavaScriptBridge* jsBridge, |