shithub: sysbench

ref: 00128bc62f7b3d643caa11754e96387ac8e0830d
dir: /bench.h/

View raw version
typedef struct BItem BItem;
typedef struct BResult BResult;
typedef struct B B;

// single benchmark function
struct BItem
{
	char *name;
	void (*fn)(B*);
};

// result of benchmarking
struct BResult
{
	int N;
	vlong ns;
	uvlong cycles;
	vlong overhead;
};

// 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 */
	vlong overheadns;	/* cost of doing 0 iters */
	vlong overheadcy;	/* cost of doing 0 iters, cycles */
	BItem item;
};

extern int NPROC;

#define BM(func)	bench("func", func)
#define XBM(func, init)	xbench("func", func, init) 

// public api
void benchinit(int, char**);
void bench(char *name, void (*)(B*));
void xbench(char *name, void(*)(B*), void (*)(void));
void benchitems(BItem[], int);