ref: a1c8da91f18c8bd3cdc7ce36c70538969e0c5602
dir: /bench.h/
#include <stdint.h>
#include <unistd.h>
typedef int64_t vlong;
typedef uint64_t uvlong;
typedef struct BItem BItem;
typedef struct B B;
// single benchmark function
struct BItem
{
char *name;
void (*fn)(B*);
};
// type passed to bench functions
struct B
{
int N;
vlong start; /* start ns */
vlong ns; /* duration */
uvlong scycles; /* start cycles */
uvlong ecycles; /* end cycles */
uvlong bcycles; /* best cycles */
long *histo; /* histogram */
int nhisto; /* histogram size */
vlong overheadns; /* cost of doing 0 iters */
vlong overheadcy; /* cost of doing 0 iters, cycles */
BItem item;
};
extern int NPROC;
enum {
KiB = 1024,
MiB = 1024*KiB,
GiB = 1024*MiB,
};
#define BM(func) bench(#func, func)
// public api
void benchinit(int, char**);
void bench(char *name, void (*)(B*));
void benchitems(BItem[], int);