bench: improve async_pummel benchmark

Benchmark the performance of uv_async_send() when the handle is contended for
by 1, 2, 4 or 8 threads.
This commit is contained in:
Ben Noordhuis 2012-07-02 03:56:18 +02:00
parent 700f1333e1
commit a2204abc8e
2 changed files with 40 additions and 7 deletions

View File

@ -43,13 +43,19 @@ static void pummel(void* arg) {
}
BENCHMARK_IMPL(async_pummel) {
static int test_async_pummel(int nthreads) {
uv_thread_t* tids;
uv_async_t handle;
uv_thread_t tid;
uint64_t time;
int i;
tids = calloc(nthreads, sizeof(tids[0]));
ASSERT(tids != NULL);
ASSERT(0 == uv_async_init(uv_default_loop(), &handle, async_cb));
ASSERT(0 == uv_thread_create(&tid, pummel, &handle));
for (i = 0; i < nthreads; i++)
ASSERT(0 == uv_thread_create(tids + i, pummel, &handle));
time = uv_hrtime();
@ -58,12 +64,33 @@ BENCHMARK_IMPL(async_pummel) {
time = uv_hrtime() - time;
done = 1;
ASSERT(0 == uv_thread_join(&tid));
for (i = 0; i < nthreads; i++)
ASSERT(0 == uv_thread_join(tids + i));
printf("%s callbacks in %.2f seconds (%s/sec)\n",
fmt(callbacks),
time / 1e9,
fmt(callbacks / (time / 1e9)));
return 0;
free(tids);
}
BENCHMARK_IMPL(async_pummel_1) {
return test_async_pummel(1);
}
BENCHMARK_IMPL(async_pummel_2) {
return test_async_pummel(2);
}
BENCHMARK_IMPL(async_pummel_4) {
return test_async_pummel(4);
}
BENCHMARK_IMPL(async_pummel_8) {
return test_async_pummel(8);
}

View File

@ -49,7 +49,10 @@ BENCHMARK_DECLARE (async1)
BENCHMARK_DECLARE (async2)
BENCHMARK_DECLARE (async4)
BENCHMARK_DECLARE (async8)
BENCHMARK_DECLARE (async_pummel)
BENCHMARK_DECLARE (async_pummel_1)
BENCHMARK_DECLARE (async_pummel_2)
BENCHMARK_DECLARE (async_pummel_4)
BENCHMARK_DECLARE (async_pummel_8)
BENCHMARK_DECLARE (spawn)
BENCHMARK_DECLARE (thread_create)
BENCHMARK_DECLARE (million_timers)
@ -117,7 +120,10 @@ TASK_LIST_START
BENCHMARK_ENTRY (async2)
BENCHMARK_ENTRY (async4)
BENCHMARK_ENTRY (async8)
BENCHMARK_ENTRY (async_pummel)
BENCHMARK_ENTRY (async_pummel_1)
BENCHMARK_ENTRY (async_pummel_2)
BENCHMARK_ENTRY (async_pummel_4)
BENCHMARK_ENTRY (async_pummel_8)
BENCHMARK_ENTRY (spawn)
BENCHMARK_ENTRY (thread_create)