shithub: sysbench

ref: 16a2cc57f9cd49f84db08e9c46478d8d0acfdf45
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;

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 xbench(char *name, void(*)(B*), void (*)(void));
void benchitems(BItem[], int);