flint: add context switch benchmark

This commit is contained in:
Dmitry Simonenko 2016-11-25 14:38:24 +03:00
parent 73c1f35a30
commit 3472bc8ed0
1 changed files with 49 additions and 0 deletions

49
tests/test_benchmark.c Normal file
View File

@ -0,0 +1,49 @@
/*
* machinarium.
*
* Cooperative multitasking engine.
*/
/*
* This example shows fiber context switch (yield)
* performance done in one second.
*/
#include <machinarium.h>
static int csw = 0;
static void
benchmark_worker(void *arg)
{
mm_t env = arg;
printf("worker started.\n");
while (mm_is_online(env)) {
csw++;
mm_sleep(env, 0);
}
printf("worker done.\n");
}
static void
benchmark_runner(void *arg)
{
mm_t env = arg;
printf("benchmark started.\n");
mm_create(env, benchmark_worker, env);
mm_sleep(env, 1000);
printf("done.\n");
printf("context switches %d in 1 sec.\n", csw);
mm_stop(env);
}
int
main(int argc, char *argv[])
{
mm_t env = mm_new();
mm_create(env, benchmark_runner, env);
mm_start(env);
mm_free(env);
return 0;
}