Fix benchmarks to not take forever on slower chips.

This commit is contained in:
Adam Ierymenko 2020-08-06 09:48:07 -07:00
parent 78670aea58
commit ae13983b10
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3

View file

@ -1282,27 +1282,37 @@ extern "C" const char *ZTT_benchmarkCrypto()
ZT_T_PRINTF("[crypto] Benchmarking AES-CTR..."); ZT_T_PRINTF("[crypto] Benchmarking AES-CTR...");
AES aes(AES_CTR_TEST_VECTOR_0_KEY); AES aes(AES_CTR_TEST_VECTOR_0_KEY);
AES::CTR ctr(aes); AES::CTR ctr(aes);
int64_t start = now(); int64_t end, start = now();
for (long i = 0; i < 350000; ++i) { unsigned long reps = 0;
for (;;) {
ctr.init(AES_CTR_TEST_VECTOR_0_IV, tmp); ctr.init(AES_CTR_TEST_VECTOR_0_IV, tmp);
ctr.crypt(tmp, sizeof(tmp)); ctr.crypt(tmp, sizeof(tmp));
ctr.finish(); ctr.finish();
if (unlikely((++reps & 0xffffU) == 0xffffU)) {
end = now();
if ((end - start) > 4000)
break;
}
} }
int64_t end = now();
foo = tmp[0]; // prevent optimization foo = tmp[0]; // prevent optimization
ZT_T_PRINTF("%.4f MiB/sec" ZT_EOL_S, ((16384.0 * 350000.0) / 1048576.0) / ((double)(end - start) / 1000.0)); ZT_T_PRINTF(" %.4f MiB/sec" ZT_EOL_S, ((16384.0 * (double)reps) / 1048576.0) / ((double)(end - start) / 1000.0));
ZT_T_PRINTF("[crypto] Benchmarking AES-GMAC..."); ZT_T_PRINTF("[crypto] Benchmarking AES-GMAC...");
AES::GMAC gmac(aes); AES::GMAC gmac(aes);
start = now(); start = now();
for (long i = 0; i < 350000; ++i) { reps = 0;
for (;;) {
gmac.init(tag); gmac.init(tag);
gmac.update(tmp, sizeof(tmp)); gmac.update(tmp, sizeof(tmp));
gmac.finish(tag); gmac.finish(tag);
} if (unlikely((++reps & 0xffffU) == 0xffffU)) {
end = now(); end = now();
if ((end - start) > 4000)
break;
}
}
foo = tag[0]; // prevent optimization foo = tag[0]; // prevent optimization
ZT_T_PRINTF("%.4f MiB/sec" ZT_EOL_S, ((16384.0 * 350000.0) / 1048576.0) / ((double)(end - start) / 1000.0)); ZT_T_PRINTF(" %.4f MiB/sec" ZT_EOL_S, ((16384.0 * (double)reps) / 1048576.0) / ((double)(end - start) / 1000.0));
} }
{ {