mirror of https://github.com/yandex/odyssey.git
machinarium: add examples/benchmark.c
This commit is contained in:
parent
d64a736e36
commit
f4b7424190
|
@ -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)
|
||||
{
|
||||
machine_t machine = arg;
|
||||
printf("worker started.\n");
|
||||
while (machine_active(machine)) {
|
||||
csw++;
|
||||
machine_sleep(machine, 0);
|
||||
}
|
||||
printf("worker done.\n");
|
||||
}
|
||||
|
||||
static void
|
||||
benchmark_runner(void *arg)
|
||||
{
|
||||
machine_t machine = arg;
|
||||
printf("benchmark started.\n");
|
||||
machine_create_fiber(machine, benchmark_worker, machine);
|
||||
machine_sleep(machine, 1000);
|
||||
printf("done.\n");
|
||||
printf("context switches %d in 1 sec.\n", csw);
|
||||
machine_stop(machine);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
machine_t machine = machine_create();
|
||||
machine_create_fiber(machine, benchmark_runner, machine);
|
||||
machine_start(machine);
|
||||
machine_free(machine);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
CC = gcc
|
||||
RM = rm
|
||||
CFLAGS = -I. -Wall -g -O0 -I../src
|
||||
LFLAGS_LIB = ../src/libmachinarium.a -pthread -lssl -lcrypto
|
||||
LFLAGS = $(LFLAGS_LIB)
|
||||
EXAMPLES = benchmark
|
||||
all: clean $(EXAMPLES)
|
||||
benchmark:
|
||||
$(CC) $(CFLAGS) benchmark.c $(LFLAGS) -o benchmark
|
||||
clean:
|
||||
$(RM) -f $(EXAMPLES)
|
Loading…
Reference in New Issue