Last active
January 29, 2023 20:15
-
-
Save lpereira/912f0128f469ad0069d0b55dd30b0ed6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* link with liblwan and google benchmark */ | |
#include <stdbool.h> | |
#include <stdio.h> | |
#include <benchmark/benchmark.h> | |
extern "C" { | |
#include <lwan-coro.h> | |
} | |
struct coro *coro; | |
static int coro_fn(struct coro *coro, void *data) | |
{ | |
while (true) { | |
coro_yield(coro, 0); | |
} | |
} | |
static void coroswitch(benchmark::State& state) | |
{ | |
while (state.KeepRunning()) { | |
benchmark::DoNotOptimize(coro_resume(coro)); | |
} | |
} | |
int main(int argc, char *argv[]) | |
{ | |
struct coro_switcher switcher; | |
coro = coro_new(&switcher, coro_fn, NULL); | |
if (!coro) | |
return 1; | |
benchmark::RegisterBenchmark("coroswitch", coroswitch); | |
benchmark::Initialize(&argc, argv); | |
benchmark::RunSpecifiedBenchmarks(); | |
coro_free(coro); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment