Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
bench: improve async_pummel benchmark
Browse files Browse the repository at this point in the history
Benchmark the performance of uv_async_send() when the handle is contended for
by 1, 2, 4 or 8 threads.
  • Loading branch information
bnoordhuis committed Jul 2, 2012
1 parent 700f133 commit a2204ab
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
37 changes: 32 additions & 5 deletions test/benchmark-async-pummel.c
Expand Up @@ -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();

Expand All @@ -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);
}
10 changes: 8 additions & 2 deletions test/benchmark-list.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a2204ab

Please sign in to comment.