X Tutup
// 2018/8/31 contributed by Guannan // // Examples to test different threadpool implementations: // - SimpleThreadpool // - ProactiveThreadpool #include #include #include // Procedure: benchmark_empty_jobs void benchmark_empty_jobs() { std::cout << "Benchmarking threadpool throughput on empty jobs ...\n"; unsigned thread_num = 4; unsigned int task_num = 10000000; auto start = std::chrono::high_resolution_clock::now(); tf::ProactiveThreadpool proactive(thread_num); for(size_t i=0; i(end - start); std::cout << "ProactiveThreadpool elapsed time: " << elapsed.count() << " ms\n"; start = std::chrono::high_resolution_clock::now(); tf::SimpleThreadpool simple(thread_num); for(size_t i=0; i(end - start); std::cout << "SimpleThreadpool elapsed time: " << elapsed.count() << " ms\n"; } // Procedure: benchmark_atomic_add void benchmark_atomic_add() { std::cout << "Benchmarking threadpool throughput on atomic add ...\n"; unsigned thread_num = 4; unsigned int task_num = 10000000; std::atomic counter(0); auto start = std::chrono::high_resolution_clock::now(); tf::ProactiveThreadpool proactive(thread_num); for(size_t i=0; i(end - start); std::cout << "ProactiveThreadpool elapsed time: " << elapsed.count() << " ms\n"; counter = 0; start = std::chrono::high_resolution_clock::now(); tf::SimpleThreadpool simple(thread_num); for(size_t i=0; i(end - start); std::cout << "SimpleThreadpool elapsed time: " << elapsed.count() << " ms\n"; } // Function: main int main(int argc, char* argv[]) { benchmark_empty_jobs(); benchmark_atomic_add(); return 0; }
X Tutup