ref: 066c7e81fb7dc81494f90831b437e646de095853
parent: 02f047daee598f22e641365d01934973b14f89f3
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Wed Oct 28 08:50:09 EDT 2020
better formatting; better percentiles
--- a/b.c
+++ b/b.c
@@ -6,7 +6,8 @@
#define MAX(a,b) ((a)>(b)?(a):(b))
enum {
- Btime = 1000000000ULL/10ULL,
+ OneS = 1000000000ULL,
+ Btime = OneS/10ULL,
Bstepmin = 100,
};
@@ -18,7 +19,7 @@
uvlong div;
/* this is ugly */
- for(div = 1000000000ULL; x < 0x1999999999999999ULL && div > 1 ; div /= 10ULL, x *= 10ULL);
+ for(div = OneS; x < 0x1999999999999999ULL && div > 1 ; div /= 10ULL, x *= 10ULL);
return x / (_tos->cyclefreq / div);
}
@@ -30,7 +31,7 @@
b = va_arg(f->args, B*);
- return fmtprint(f, "%zd", 1000000000ULL/(b->tot.ns/b->ic));
+ return fmtprint(f, "%zd", OneS/(b->tot.ns/b->ic));
}
static int
@@ -83,6 +84,7 @@
benchcalc(B *b)
{
uvlong m;
+ int i, n;
qsort(b->c, b->ic, sizeof(*b->c), ccmp);
@@ -94,9 +96,10 @@
b->avg.ns = cycles2ns(b->avg.c = b->tot.c / b->step);
b->min.ns = cycles2ns(b->min.c = b->c[0]);
b->max.ns = cycles2ns(b->max.c = b->c[b->ic-1]);
- b->p96.ns = cycles2ns(b->c[b->ic*96 / 100]);
- b->p98.ns = cycles2ns(b->c[b->ic*98 / 100]);
- b->p99.ns = cycles2ns(b->c[b->ic*99 / 100]);
+ for(i = 1; i < 100; i++){
+ n = MAX(0, b->ic*i/100 - 1);
+ b->p[i].ns = cycles2ns(b->c[n]);
+ }
}
void
@@ -138,20 +141,21 @@
void
benchprint(B *b, int nb, int fd)
{
- static char *header[] = {" ", "op/s", "99%", "98%", "96%", "med", "avg", "min"};
- static int w[] = {16, 8, 8, 8, 8, 8, 8, 8};
+ static char *header[] = {" ", "op/s", "98%", "96%", "75%", "med", "avg", "min", "max"};
+ static int w[] = {16, 8, 8, 8, 8, 8, 8, 8, 8};
static int off[] = {
0,
0,
- offsetof(B, p99),
- offsetof(B, p98),
- offsetof(B, p96),
+ offsetof(B, p[99]),
+ offsetof(B, p[95]),
+ offsetof(B, p[75]),
offsetof(B, med),
offsetof(B, avg),
offsetof(B, min),
+ offsetof(B, max),
};
- char t[32], *s, *p;
- int i, j, n;
+ char t[64], *s, *p;
+ int i, j, n, x;
for(i = 0; i < nb; i++){
w[0] = MAX(w[0], snprint(t, sizeof(t), "%s ", b[i].name ? b[i].name : ""));
@@ -164,8 +168,10 @@
n += w[j];
s = malloc(n+1);
memset(s, ' ', n);
- for(j = 0, p = s; j < nelem(header); p += w[j++])
- p[sprint(p, "%s", header[j])] = ' ';
+ for(j = 0, p = s; j < nelem(header); p += w[j++]){
+ x = snprint(t, sizeof(t), "%s ", header[j]);
+ memmove(p+w[j]-x, t, x);
+ }
*p = 0;
fprint(fd, "%s\n", s);
@@ -174,10 +180,13 @@
p = s;
p[sprint(p, "%s ", b[i].name)] = ' ';
p += w[0];
- p[snprint(p, sizeof(t), "%σ ", &b[i])] = ' ';
+ x = snprint(t, sizeof(t), "%σ ", b+i);
+ memmove(p+w[1]-x, t, x);
p += w[1];
- for(j = 2; j < nelem(header); p += w[j], j++)
- p[sprint(p, "%τ ", *(Cns*)((char*)(b+i) + off[j]))] = ' ';
+ for(j = 2; j < nelem(header); p += w[j], j++){
+ x = snprint(t, sizeof(t), "%τ ", *(Cns*)((char*)(b+i) + off[j]));
+ memmove(p+w[j]-x, t, x);
+ }
*p = 0;
fprint(fd, "%s\n", s);
}
--- a/b.h
+++ b/b.h
@@ -16,8 +16,8 @@
uvlong step;
uvlong t0;
Cns tot, avg, med, min, max;
- Cns p96, p98, p99;
- u32int *c;
+ Cns p[100];
+ uvlong *c;
int nc, ic;
char *name;
};