1 #include "benchmarks.h"
5 static uint8_t buf[512];
7 void hash_benchmark(Hash *h, const char *hname, int numk)
9 memset(buf, 0x12, sizeof(buf));
10 ticks_t t = timer_clock();
12 for (int j=0;j<64;++j) {
14 for (int i=0; i<numk*2; ++i)
15 hash_update(h, buf, 512);
19 t = timer_clock() - t;
21 utime_t usec = ticks_to_us(t) / 64;
22 kprintf("%s @ %ldMhz: %s of %dKiB of data: %lu.%lu ms\n", CPU_CORE_NAME, CPU_FREQ/1000000, hname, numk, (usec/1000), (usec % 1000));
25 void prng_benchmark(PRNG *prng, const char *hname, int numbytes)
27 memset(buf, 0x12, sizeof(buf));
29 ASSERT(sizeof(buf) >= prng_seed_len(prng));
30 prng_reseed(prng, buf);
32 ticks_t t = timer_clock();
33 enum { CYCLES = 2048 };
35 for (int j=0;j<CYCLES;++j)
37 for (int i=0; i<(numbytes+511)/512-1; ++i)
38 prng_generate(prng, buf, 512);
40 prng_generate(prng, buf, numbytes%512);
43 t = timer_clock() - t;
45 utime_t usec = ticks_to_us(t) / CYCLES;
46 kprintf("%s @ %ldMhz: %s generation of %d random bytes: %lu.%lu ms\n", CPU_CORE_NAME, CPU_FREQ/1000000, hname, numbytes, (usec/1000), (usec % 1000));
47 kprintf("Sample of random data:\n");
48 kdump(buf, MIN(numbytes, 64));
51 void cipher_benchmark(BlockCipher *c, const char *cname, int numbytes)
53 memset(buf, 0x12, sizeof(buf));
55 ASSERT(sizeof(buf) >= cipher_key_len(c));
56 cipher_set_key(c, buf);
58 uint8_t iv[cipher_block_len(c)];
59 memset(iv, 0, sizeof(iv));
61 ticks_t t = timer_clock();
64 for (int j=0;j<CYCLES;++j)
66 cipher_cbc_begin(c, iv);
67 int numblocks = (numbytes / cipher_block_len(c)) + 1;
68 for (int i=0; i<numblocks; ++i)
69 cipher_cbc_encrypt(c, buf);
72 t = timer_clock() - t;
74 utime_t usec = ticks_to_us(t) / CYCLES;
75 kprintf("%s @ %ldMhz: %s-CBC of %d bytes: %lu.%lu ms (%d KiB/s)\n",
76 CPU_CORE_NAME, CPU_FREQ/1000000,
78 (usec/1000), (usec % 1000),
79 (uint32_t)(numbytes * (CYCLES * 1000000 / 1024) / ticks_to_us(t)));