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

Function main

ccan/ccan/htable/tools/stringspeed.c:44–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44int main(int argc, char *argv[])
45{
46 size_t i, j, num;
47 struct timeabs start, stop;
48 struct htable_str ht;
49 char **words, **misswords;
50
51 words = tal_strsplit(NULL, grab_file(NULL,
52 argv[1] ? argv[1] : "/usr/share/dict/words"), "\n",
53 STR_NO_EMPTY);
54 htable_str_init(&ht);
55 num = tal_count(words) - 1;
56 /* Note that on my system, num is just > 98304, where we double! */
57 printf("%zu words\n", num);
58
59 /* Append and prepend last char for miss testing. */
60 misswords = tal_arr(words, char *, num);
61 for (i = 0; i < num; i++) {
62 char lastc;
63 if (strlen(words[i]))
64 lastc = words[i][strlen(words[i])-1];
65 else
66 lastc = 'z';
67 misswords[i] = tal_fmt(misswords, "%c%s%c%c",
68 lastc, words[i], lastc, lastc);
69 }
70
71 printf("#01: Initial insert: ");
72 fflush(stdout);
73 start = time_now();
74 for (i = 0; i < num; i++)
75 htable_str_add(&ht, words[i]);
76 stop = time_now();
77 printf(" %zu ns\n", normalize(&start, &stop, num));
78
79 printf("Bytes allocated: %zu\n",
80 sizeof(ht.raw.table[0]) << ht.raw.bits);
81
82 printf("#02: Initial lookup (match): ");
83 fflush(stdout);
84 start = time_now();
85 for (i = 0; i < num; i++)
86 if (htable_str_get(&ht, words[i]) != words[i])
87 abort();
88 stop = time_now();
89 printf(" %zu ns\n", normalize(&start, &stop, num));
90
91 printf("#03: Initial lookup (miss): ");
92 fflush(stdout);
93 start = time_now();
94 for (i = 0; i < num; i++) {
95 if (htable_str_get(&ht, misswords[i]))
96 abort();
97 }
98 stop = time_now();
99 printf(" %zu ns\n", normalize(&start, &stop, num));
100
101 /* Lookups in order are very cache-friendly for judy; try random */

Callers

nothing calls this directly

Calls 4

grab_fileFunction · 0.85
time_nowFunction · 0.85
abortFunction · 0.85
normalizeFunction · 0.70

Tested by

no test coverage detected