]> git.ozlabs.org Git - ccan/blob - ccan/crypto/sha256/benchmarks/double-sha-bench.c
crypto/sha256: add benchmark.
[ccan] / ccan / crypto / sha256 / benchmarks / double-sha-bench.c
1 /* Bitcoin does a lot of SHA of SHA.  Benchmark that. */
2 #include <ccan/crypto/sha256/sha256.h>
3 #include <ccan/time/time.h>
4 #include <stdio.h>
5
6 int main(int argc, char *argv[])
7 {
8         struct timeabs start;
9         struct timerel diff;
10         size_t i, n;
11         struct sha256 h;
12
13         n = atoi(argv[1] ? argv[1] : "1000000");
14         sha256(&h, &n, sizeof(n));
15         start = time_now();
16         for (i = 0; i < n; i++)
17                 sha256(&h, &h, sizeof(h));
18         diff = time_divide(time_between(time_now(), start), n);
19         printf("Hashing time for %02x%02x%02x%02x%02x%02x... is %llu nsec\n",
20                h.u.u8[0], h.u.u8[1], h.u.u8[2], h.u.u8[3], h.u.u8[4], h.u.u8[5],
21                (unsigned long long)time_to_nsec(diff));
22         return 0;
23 }