btrfs-progs: crypto: print throughput in hash-speedtest

Calculate the estimated throughput as a number that's comparable across
machines.

  $ ./hash-speedtest --cycles
  Block size:     4096
  Iterations:     100000
  Implementation: builtin
  Units:          cycles

      NULL-NOP: cycles:     42928902, cycles/i      429
   NULL-MEMCPY: cycles:     73014868, cycles/i      730,    18651.186 MiB/s
	CRC32C: cycles:    182293290, cycles/i     1822,     7470.579 MiB/s
	XXHASH: cycles:    138085981, cycles/i     1380,     9862.272 MiB/s
	SHA256: cycles:  10576270837, cycles/i   105762,      128.764 MiB/s
       BLAKE2b: cycles:   2263761293, cycles/i    22637,      601.585 MiB/s

  $ ./hash-speedtest --time
  Block size:     4096
  Iterations:     100000
  Implementation: builtin
  Units:          nsecs

      NULL-NOP: nsecs:     12164607, nsecs/i      121
   NULL-MEMCPY: nsecs:     20423641, nsecs/i      204,    19095.518 MiB/s
	CRC32C: nsecs:     51972794, nsecs/i      519,     7503.926 MiB/s
	XXHASH: nsecs:     38935164, nsecs/i      389,    10016.651 MiB/s
	SHA256: nsecs:   3030944497, nsecs/i    30309,      128.673 MiB/s
       BLAKE2b: nsecs:    648489262, nsecs/i     6484,      601.398 MiB/s

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-05-26 23:09:52 +02:00
parent 55bf9b749d
commit 133dd6c6c3

View File

@ -87,6 +87,7 @@ int main(int argc, char **argv) {
int (*digest)(const u8 *buf, size_t length, u8 *out);
int digest_size;
u64 cycles;
u64 time;
} contestants[] = {
{ .name = "NULL-NOP", .digest = hash_null_nop, .digest_size = 32 },
{ .name = "NULL-MEMCPY", .digest = hash_null_memcpy, .digest_size = 32 },
@ -145,24 +146,41 @@ int main(int argc, char **argv) {
for (idx = 0; idx < ARRAY_SIZE(contestants); idx++) {
struct contestant *c = &contestants[idx];
u64 start, end;
u64 tstart, tend;
u64 total;
printf("% 12s: ", c->name);
fflush(stdout);
start = (units ? get_time() : get_cycles());
tstart = get_time();
start = get_cycles();
for (iter = 0; iter < iterations; iter++) {
memset(buf, iter & 0xFF, blocksize);
memset(hash, 0, 32);
c->digest(buf, blocksize, hash);
}
end = (units ? get_time() : get_cycles());
end = get_cycles();
tend = get_time();
c->cycles = end - start;
c->time = tend - tstart;
printf("%: % 12llu, %s/i % 8llu\n",
units_to_str(units),
(unsigned long long)c->cycles,
units_to_str(units),
(unsigned long long)c->cycles / iterations);
if (units == 0)
total = c->cycles;
if (units == 1)
total = c->time;
printf("%s: % 12llu, %s/i % 8llu",
units_to_str(units), total,
units_to_str(units), total / iterations);
if (idx > 0) {
float t;
float mb;
t = (float)c->time / 1000 / 1000 / 1000;
mb = blocksize * iterations / 1024 / 1024;
printf(", % 12.3f MiB/s", mb / t);
}
putchar('\n');
}
return 0;