MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

ccan/ccan/strset/tools/speed.c:42–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42int main(int argc, char *argv[])
43{
44 size_t i, j, num;
45 struct timeabs start, stop;
46 struct strset set;
47 char **words, **misswords;
48
49 words = tal_strsplit(NULL, grab_file(NULL,
50 argv[1] ? argv[1] : "/usr/share/dict/words"),
51 "\n", STR_NO_EMPTY);
52 strset_init(&set);
53 num = tal_count(words) - 1;
54 printf("%zu words\n", num);
55
56 /* Append and prepend last char for miss testing. */
57 misswords = tal_arr(words, char *, num);
58 for (i = 0; i < num; i++) {
59 char lastc;
60 if (strlen(words[i]))
61 lastc = words[i][strlen(words[i])-1];
62 else
63 lastc = 'z';
64 misswords[i] = tal_fmt(misswords, "%c%s%c%c",
65 lastc, words[i], lastc, lastc);
66 }
67
68 printf("#01: Initial insert: ");
69 fflush(stdout);
70 start = time_now();
71 for (i = 0; i < num; i++)
72 strset_add(&set, words[i]);
73 stop = time_now();
74 printf(" %zu ns\n", normalize(&start, &stop, num));
75
76#if 0
77 printf("Nodes allocated: %zu (%zu bytes)\n",
78 allocated, allocated * sizeof(critbit0_node));
79#endif
80
81 printf("#02: Initial lookup (match): ");
82 fflush(stdout);
83 start = time_now();
84 for (i = 0; i < num; i++)
85 if (!strset_get(&set, words[i]))
86 abort();
87 stop = time_now();
88 printf(" %zu ns\n", normalize(&start, &stop, num));
89
90 printf("#03: Initial lookup (miss): ");
91 fflush(stdout);
92 start = time_now();
93 for (i = 0; i < num; i++) {
94 if (strset_get(&set, misswords[i]))
95 abort();
96 }
97 stop = time_now();
98 printf(" %zu ns\n", normalize(&start, &stop, num));
99

Callers

nothing calls this directly

Calls 8

grab_fileFunction · 0.85
strset_initFunction · 0.85
time_nowFunction · 0.85
strset_addFunction · 0.85
strset_getFunction · 0.85
abortFunction · 0.85
strset_delFunction · 0.85
normalizeFunction · 0.70

Tested by

no test coverage detected