odyssey/tests/benchmark.c

50 lines
889 B
C
Raw Normal View History

2016-11-25 11:38:24 +00:00
/*
* 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)
{
machine_t machine = arg;
2016-11-25 11:38:24 +00:00
printf("worker started.\n");
while (machine_active(machine)) {
2016-11-25 11:38:24 +00:00
csw++;
machine_sleep(machine, 0);
2016-11-25 11:38:24 +00:00
}
printf("worker done.\n");
}
static void
benchmark_runner(void *arg)
{
machine_t machine = arg;
2016-11-25 11:38:24 +00:00
printf("benchmark started.\n");
machine_create_fiber(machine, benchmark_worker, machine);
machine_sleep(machine, 1000);
2016-11-25 11:38:24 +00:00
printf("done.\n");
printf("context switches %d in 1 sec.\n", csw);
machine_stop(machine);
2016-11-25 11:38:24 +00:00
}
int
main(int argc, char *argv[])
{
machine_t machine = machine_create();
machine_create_fiber(machine, benchmark_runner, machine);
machine_start(machine);
machine_free(machine);
2016-11-25 11:38:24 +00:00
return 0;
}