Skip to content

Instantly share code, notes, and snippets.

@lpereira
Last active January 29, 2023 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lpereira/912f0128f469ad0069d0b55dd30b0ed6 to your computer and use it in GitHub Desktop.
Save lpereira/912f0128f469ad0069d0b55dd30b0ed6 to your computer and use it in GitHub Desktop.
/* 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