1 /* Test speed of memiszero */
2 #include <ccan/time/time.h>
3 #include <ccan/mem/mem.h>
10 int main(int argc, char *argv[])
12 size_t n, i, max = argv[1] ? atol(argv[1]) : 100000000, runs;
16 arr = calloc(1, max + MAX_TEST + 1);
19 /* First test even sizes case. */
20 for (n = 1; n <= MAX_TEST; n *= 2) {
21 struct timeabs start = time_now();
24 for (i = 0; i < runs; i++)
25 total += memeqzero(arr + i, n);
26 each = time_divide(time_between(time_now(), start), runs);
27 assert(each.ts.tv_sec == 0);
28 printf("%zu: %uns\n", n, (unsigned int)each.ts.tv_nsec);
30 /* Reduce runs over time, as bigger take longer. */
35 for (n = 1; n <= MAX_TEST; n *= 2) {
36 struct timeabs start = time_now();
39 for (i = 0; i < runs; i++)
40 total += memeqzero(arr + i, n+1);
41 each = time_divide(time_between(time_now(), start), runs);
42 assert(each.ts.tv_sec == 0);
43 printf("%zu: %uns\n", n+1, (unsigned int)each.ts.tv_nsec);
47 printf("total = %zu\n", total);