| 148 | } |
| 149 | |
| 150 | static void LatencyTest(int loop_count, bool slow_add) |
| 151 | { |
| 152 | int64_t total_latency = 0; |
| 153 | int64_t total_add_latency = 0; |
| 154 | { |
| 155 | ThreadPool threadpool; |
| 156 | for (int i = 0; i < loop_count; ++i) |
| 157 | { |
| 158 | int64_t t0 = RealtimeClock.MicroSeconds(); |
| 159 | threadpool.AddTask(std::bind(LatencyProc, &total_latency, t0)); |
| 160 | int64_t t1 = RealtimeClock.MicroSeconds(); |
| 161 | total_add_latency += t1 - t0; |
| 162 | if (slow_add) |
| 163 | ThisThread::Sleep(0); |
| 164 | } |
| 165 | } |
| 166 | printf("average latency = %g\n", 1.0 * total_latency / loop_count); |
| 167 | printf("average add latency = %g\n", 1.0 * total_add_latency / loop_count); |
| 168 | } |
| 169 | |
| 170 | TEST(ThreadPool, FastAddLatency) |
| 171 | { |
no test coverage detected