Do a simpler boring bench
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
54
src/bench.c
54
src/bench.c
@@ -51,25 +51,24 @@ gt_bench(int argc, char **argv)
|
|||||||
|
|
||||||
if (term) {
|
if (term) {
|
||||||
printf("cipher: %s\n\n", chacha ? "chacha20poly1305" : "aegis256");
|
printf("cipher: %s\n\n", chacha ? "chacha20poly1305" : "aegis256");
|
||||||
printf(" %5s %9s %9s\n", "size", "mean", "sigma");
|
printf(" size min mean max \n");
|
||||||
printf("---------------------------------\n");
|
printf("----------------------------------------------------\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 20;
|
int64_t size = 20;
|
||||||
|
|
||||||
for (int i = 0; !gt_quit && size <= 1450; i++) {
|
for (int i = 0; !gt_quit && size <= 1450; i++) {
|
||||||
struct {
|
struct {
|
||||||
int64_t d, n, m, v, s;
|
int64_t min, mean, max, n;
|
||||||
} s = { .n = 0 };
|
} mbps = { .n = 0 };
|
||||||
|
|
||||||
while (!gt_quit && s.n < 5) {
|
int64_t bytes_max = (int64_t)1 << 20;
|
||||||
alarm(1);
|
|
||||||
gt_alarm = 0;
|
|
||||||
|
|
||||||
|
while (!gt_quit && mbps.n < 10) {
|
||||||
int64_t bytes = 0;
|
int64_t bytes = 0;
|
||||||
clock_t base = clock();
|
int64_t base = (int64_t)clock();
|
||||||
|
|
||||||
while (!gt_alarm && !(bytes >> 32)) {
|
while (!gt_quit && bytes <= bytes_max) {
|
||||||
if (chacha) {
|
if (chacha) {
|
||||||
crypto_aead_chacha20poly1305_encrypt(
|
crypto_aead_chacha20poly1305_encrypt(
|
||||||
buf, NULL, buf, size, NULL, 0, NULL, npub, key);
|
buf, NULL, buf, size, NULL, 0, NULL, npub, key);
|
||||||
@@ -79,31 +78,28 @@ gt_bench(int argc, char **argv)
|
|||||||
bytes += size;
|
bytes += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t mbps = (8 * bytes * CLOCKS_PER_SEC)
|
int64_t dt = (int64_t)clock() - base;
|
||||||
/ ((clock() - base) * 1000 * 1000);
|
bytes_max = (bytes * (CLOCKS_PER_SEC / 4)) / dt;
|
||||||
|
int64_t _mbps = (8 * bytes * CLOCKS_PER_SEC) / (dt * 1000 * 1000);
|
||||||
|
|
||||||
alarm(0);
|
if (!mbps.n++) {
|
||||||
|
mbps.min = _mbps;
|
||||||
if (mbps <= 0)
|
mbps.max = _mbps;
|
||||||
continue;
|
mbps.mean = _mbps;
|
||||||
|
|
||||||
if (!s.n++) {
|
|
||||||
s.m = mbps;
|
|
||||||
s.d = 0;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t d1 = mbps - s.m; s.m += d1 / s.n;
|
if (mbps.min > _mbps)
|
||||||
int64_t d2 = mbps - s.m; s.d += d1 * d2;
|
mbps.min = _mbps;
|
||||||
|
|
||||||
s.v = s.d / (s.n - 1);
|
if (mbps.max < _mbps)
|
||||||
s.s = 1 + (s.v - 1) / 2;
|
mbps.max = _mbps;
|
||||||
|
|
||||||
while (s.s && s.s * s.s > s.v)
|
mbps.mean += (_mbps - mbps.mean) / mbps.n;
|
||||||
s.s = (s.s + s.v / s.s) / 2;
|
|
||||||
|
|
||||||
if (term) {
|
if (term) {
|
||||||
printf("\r %5"PRIi64" %9"PRIi64" Mbps %9"PRIi64, size, s.m, s.s);
|
printf("\r %5"PRIi64" %9"PRIi64" Mbps %9"PRIi64" Mbps %9"PRIi64" Mbps",
|
||||||
|
size, mbps.min, mbps.mean, mbps.max);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,10 +107,12 @@ gt_bench(int argc, char **argv)
|
|||||||
if (term) {
|
if (term) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
} else {
|
} else {
|
||||||
printf("bench %"PRIi64" %"PRIi64" %"PRIi64"\n", size, s.m, s.s);
|
printf("bench %s %"PRIi64" %"PRIi64" %"PRIi64" %"PRIi64"\n",
|
||||||
|
chacha ? "chacha20poly1305" : "aegis256",
|
||||||
|
size, mbps.min, mbps.mean, mbps.max);
|
||||||
}
|
}
|
||||||
|
|
||||||
size += 2 * 11 * 13;
|
size += 2 * 5 * 13;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user