]> git.ozlabs.org Git - ccan/blob - ccan/mem/bench/speed.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / mem / bench / speed.c
1 /* Test speed of memiszero */
2 #include <ccan/time/time.h>
3 #include <ccan/mem/mem.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <assert.h>
7
8 #define MAX_TEST 65536
9
10 int main(int argc, char *argv[])
11 {
12         size_t n, i, max = argv[1] ? atol(argv[1]) : 100000000, runs;
13         char *arr;
14         size_t total = 0;
15
16         arr = calloc(1, max + MAX_TEST + 1);
17
18         runs = max;
19         /* First test even sizes case. */
20         for (n = 1; n <= MAX_TEST; n *= 2) {
21                 struct timeabs start = time_now();
22                 struct timerel each;
23
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);
29
30                 /* Reduce runs over time, as bigger take longer. */
31                 runs = runs * 2 / 3;
32         }
33
34         runs = max;
35         for (n = 1; n <= MAX_TEST; n *= 2) {
36                 struct timeabs start = time_now();
37                 struct timerel each;
38
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);
44                 runs = runs * 2 / 3;
45         }
46
47         printf("total = %zu\n", total);
48         return 0;
49 }