librfn
An ad-hoc utility library
benchmark.c
Go to the documentation of this file.
1 /*
2  * benchmark.c
3  *
4  * Part of librfn (a general utility library from redfelineninja.org.uk)
5  *
6  * Copyright (C) 2015 Daniel Thompson <daniel@redfelineninja.org.uk>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  */
13 
14 #include <assert.h>
15 #include <stdio.h>
16 #include <string.h>
17 
18 #include "librfn.h"
19 #include "libbench.h"
20 
21 typedef struct {
25 
27 {
29  static uint64_t end_time;
30  static int i;
31 
32  PT_BEGIN_FIBRE(&c->fibre);
33 
34  benchmark_init(&c->results, fibre);
35 
36  /* busy wait for two seconds to try and open up the cpufreq governor */
37  printf("Preparing ...");
38  fflush(stdout);
39  end_time = time64_now() + 2000000;
40  while (time64_now() < end_time)
41  PT_YIELD();
42  printf(" done\n");
43 
44  printf("Benchmarking ");
45  fflush(stdout);
46  for (i=0; i<50; i++) {
47  printf(".");
48  fflush(stdout);
50  }
51  printf(" done\nBenchmark completed in %4.2f seconds\n\n",
52  (time64_now() - end_time) / 1000000.0);
53 
55 
56  FILE *f = fopen("benchmark-results.csv", "w");
58  fclose(f);
59 
60  exit(0);
61  PT_END();
62 }
63 
66 };
67 
68 int main(int argc, char *argv[])
69 {
70  fibre_run(&conductor.fibre);
72 
73  return 0;
74 }
#define containerof(ptr, type, member)
Definition: util.h:35
struct charlie c
uint64_t time64_now(void)
Micro benchmark suite for some librfn features.
#define FIBRE_VAR_INIT(fn)
Static initializer for a fibre descriptor.
Definition: fibre.h:75
#define PT_SPAWN(child, thread)
Call a child thread.
Definition: protothreads.h:149
void fibre_scheduler_main_loop(void)
Definition: fibre_default.c:17
#define PT_YIELD()
Definition: protothreads.h:124
int benchmark_run_once(benchmark_results_t *results)
Definition: libbench.c:159
#define PT_END()
Definition: protothreads.h:100
int conductor_fibre(fibre_t *fibre)
Definition: benchmark.c:26
conductor_fibre_t conductor
Definition: benchmark.c:64
void benchmark_show_results(benchmark_results_t *results)
Definition: libbench.c:223
int main(int argc, char *argv[])
Definition: benchmark.c:68
void benchmark_show_csv(benchmark_results_t *results, FILE *f)
Definition: libbench.c:236
benchmark_results_t results
Definition: benchmark.c:23
void benchmark_init(benchmark_results_t *results, fibre_t *wakeup)
Definition: libbench.c:151
#define PT_BEGIN_FIBRE(f)
Fibre aware alternative to PT_BEGIN().
Definition: fibre.h:103
Fibre descriptor.
Definition: fibre.h:64
void fibre_run(fibre_t *f)
Definition: fibre.c:173