1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| void PrintMatrix(std::ostream& timeOs, MatrixType& m, int count) { for (int i = 0; i < count; ++i) { TimeGap gap{}; m.Print(); timeOs << "time use " << gap.gap() << "us " << gap.gapMs() << "ms" << std::endl; } } TEST_CASE("cout_test") { auto m = std::make_shared<MatrixType>(1000, 1000); for (int x = 0; x < 1000; ++x) { for (int y = 0; y < 1000; ++y) { m->Set(x, y, x * 100000 + y); } } std::cerr << "single " << std::endl; // 单线程 PrintMatrix(std::cerr, *m, 20); std::cerr << "multi " << std::endl;
// 多线程 tars::TC_ThreadPool m_threadPool{}; m_threadPool.init(get_nprocs() * 2); m_threadPool.start(); for (int i = 0; i < 1000; ++i) { m_threadPool.exec([m]() { PrintMatrix(std::cerr, *m, 1); }); } m_threadPool.waitForAllDone(); }
|