shithub: getest

ref: 4cff2af5a4ff459f67aaa9cadf56913171891f95
dir: /iobench.c/

View raw version
#include <u.h>
#include <libc.h>

void
runbench(Bench *b, int nb)
{
	char *unit[] = {"ns", "us", "ms", "s"};
	double oc, dt;
	vlong t0, t1;
	int i, j;

	for(i = 0; i < nb; i++){
		if(b[i].reps == 0)
			b[i].reps = 1;
		print("%15s:\t", b[i].name);
		t0 = nsec();
		oc = b[i].fn(&b[i]);
		t1 = nsec();
		dt = (t1 - t0);
		for(j = 0; j < nelem(unit)-1; j++)
			if(dt/1000 < 1)
				break;
			else
				dt /= 1000.0;
		print("%f%s (%f %s/%s)\n", dt, unit[j], (double)oc/dt, b[i].unit, unit[j]);
		sleep(10*1000);
	}
}

void
main(int argc, char **argv)
{
	Bench marks[] = {