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

Function main

ccan/ccan/strset/tools/cbspeed.c:391–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

389}
390
391int main(int argc, char *argv[])
392{
393 size_t i, j, num;
394 struct timeabs start, stop;
395 critbit0_tree ct;
396 char **words, **misswords;
397
398 words = tal_strsplit(NULL, grab_file(NULL,
399 argv[1] ? argv[1] : "/usr/share/dict/words"), "\n", STR_NO_EMPTY);
400 ct.root = NULL;
401 num = tal_count(words) - 1;
402 printf("%zu words\n", num);
403
404 /* Append and prepend last char for miss testing. */
405 misswords = tal_arr(words, char *, num);
406 for (i = 0; i < num; i++) {
407 char lastc;
408 if (strlen(words[i]))
409 lastc = words[i][strlen(words[i])-1];
410 else
411 lastc = 'z';
412 misswords[i] = tal_fmt(misswords, "%c%s%c%c",
413 lastc, words[i], lastc, lastc);
414 }
415
416 printf("#01: Initial insert: ");
417 fflush(stdout);
418 start = time_now();
419 for (i = 0; i < num; i++)
420 critbit0_insert(&ct, words[i]);
421 stop = time_now();
422 printf(" %zu ns\n", normalize(&start, &stop, num));
423
424 printf("Nodes allocated: %zu (%zu bytes)\n",
425 allocated, allocated * sizeof(critbit0_node));
426
427 printf("#02: Initial lookup (match): ");
428 fflush(stdout);
429 start = time_now();
430 for (i = 0; i < num; i++)
431 if (!critbit0_contains(&ct, words[i]))
432 abort();
433 stop = time_now();
434 printf(" %zu ns\n", normalize(&start, &stop, num));
435
436 printf("#03: Initial lookup (miss): ");
437 fflush(stdout);
438 start = time_now();
439 for (i = 0; i < num; i++) {
440 if (critbit0_contains(&ct, misswords[i]))
441 abort();
442 }
443 stop = time_now();
444 printf(" %zu ns\n", normalize(&start, &stop, num));
445
446 /* Lookups in order are very cache-friendly for judy; try random */
447 printf("#04: Initial lookup (random): ");
448 fflush(stdout);

Callers

nothing calls this directly

Calls 7

grab_fileFunction · 0.85
time_nowFunction · 0.85
critbit0_insertFunction · 0.85
critbit0_containsFunction · 0.85
abortFunction · 0.85
critbit0_deleteFunction · 0.85
normalizeFunction · 0.70

Tested by

no test coverage detected