fluent: add context switch benchmark

This commit is contained in:
Dmitry Simonenko 2016-11-08 16:04:53 +03:00
parent d4a77c147e
commit 4a38d7b7d6
2 changed files with 67 additions and 0 deletions

49
example/benchmark.c Normal file
View File

@ -0,0 +1,49 @@
/*
* fluent.
*
* Cooperative multitasking engine.
*/
/*
* This example shows fiber context switch (yield)
* performance done in one second.
*/
#include <fluent.h>
static int csw = 0;
static void
benchmark_worker(void *arg)
{
ft_t env = arg;
printf("worker started.\n");
while (ft_is_online(env)) {
csw++;
ft_sleep(env, 0);
}
printf("worker done.\n");
}
static void
benchmark_runner(void *arg)
{
ft_t env = arg;
printf("benchmark started.\n");
ft_create(env, benchmark_worker, env);
ft_sleep(env, 1000);
printf("done.\n");
printf("context switches %d in 1 sec.\n", csw);
ft_stop(env);
}
int
main(int argc, char *argv[])
{
ft_t env = ft_new();
ft_create(env, benchmark_runner, env);
ft_start(env);
ft_free(env);
return 0;
}

18
example/makefile Normal file
View File

@ -0,0 +1,18 @@
CC = gcc
RM = rm
CFLAGS = -I. -Wall -g -O0 -I../lib
LFLAGS = ../lib/libfluent.a -luv
all: validate clean benchmark
benchmark: benchmark.o
$(CC) benchmark.o $(LFLAGS) -o benchmark
validate:
@if [ ! -f ../lib/libfluent.a ]; then \
echo ""; \
echo "Please build the library first."; \
echo ""; \
exit 1; \
fi
.c.o:
$(CC) $(CFLAGS) -c $<
clean:
$(RM) -f benchmark benchmark.o