diff options
author | Ming Lei <ming.lei@canonical.com> | 2014-08-13 18:08:47 +0800 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2014-08-20 11:51:28 +0200 |
commit | 61ff8cfbec64f08f6955fe04649665f9f7eb0cc6 (patch) | |
tree | 05aea60baf0da5d8042de030ef5bdd84f935bc08 /tests/test-coroutine.c | |
parent | a1cb48a3bffdb62c429297ac7057d1ce76fc4839 (diff) |
test-coroutine: test cost introduced by coroutine
This test runs dummy function with coroutine by using
two enter and one yield since which is a common usage.
So we can see the cost introduced by corouting for running
one function, for example:
Run operation 20000000 iterations 4.841071 s, 4131K operations/s
242ns per coroutine
Signed-off-by: Ming Lei <ming.lei@canonical.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'tests/test-coroutine.c')
-rw-r--r-- | tests/test-coroutine.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/test-coroutine.c b/tests/test-coroutine.c index 6e634f4a78..e22fae170a 100644 --- a/tests/test-coroutine.c +++ b/tests/test-coroutine.c @@ -311,6 +311,35 @@ static void perf_baseline(void) maxcycles, duration); } +static __attribute__((noinline)) void perf_cost_func(void *opaque) +{ + qemu_coroutine_yield(); +} + +static void perf_cost(void) +{ + const unsigned long maxcycles = 40000000; + unsigned long i = 0; + double duration; + unsigned long ops; + Coroutine *co; + + g_test_timer_start(); + while (i++ < maxcycles) { + co = qemu_coroutine_create(perf_cost_func); + qemu_coroutine_enter(co, &i); + qemu_coroutine_enter(co, NULL); + } + duration = g_test_timer_elapsed(); + ops = (long)(maxcycles / (duration * 1000)); + + g_test_message("Run operation %lu iterations %f s, %luK operations/s, " + "%luns per coroutine", + maxcycles, + duration, ops, + (unsigned long)(1000000000 * duration) / maxcycles); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -325,6 +354,7 @@ int main(int argc, char **argv) g_test_add_func("/perf/nesting", perf_nesting); g_test_add_func("/perf/yield", perf_yield); g_test_add_func("/perf/function-call", perf_baseline); + g_test_add_func("/perf/cost", perf_cost); } return g_test_run(); } |