Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit a2204abc8eae243ca10ad1555f9934b41a02efc1 1 parent 700f133
@bnoordhuis bnoordhuis authored
Showing with 40 additions and 7 deletions.
  1. +32 −5 test/benchmark-async-pummel.c
  2. +8 −2 test/benchmark-list.h
View
37 test/benchmark-async-pummel.c
@@ -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
10 test/benchmark-list.h
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.