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

Function main

ccan/ccan/htable/tools/density.c:59–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57}
58
59int main(int argc, char *argv[])
60{
61 unsigned int i;
62 size_t num;
63 struct timeabs start, stop;
64 struct htable_ptrint ht;
65
66 if (argc != 2)
67 errx(1, "Usage: density <power-of-2-tablesize>");
68
69 num = atoi(argv[1]);
70
71 printf("Total buckets, buckets used, nanoseconds search time per element, avg run, longest run\n");
72 for (i = 1; i <= 99; i++) {
73 uintptr_t j;
74 struct htable_ptrint_iter it;
75 size_t count, avg_run, longest_run;
76 ptrint_t *p;
77
78 htable_ptrint_init_sized(&ht, num * 3 / 4);
79 assert((1 << ht.raw.bits) == num);
80
81 /* Can't put 0 or 1 in the hash table: multiply by a prime. */
82 for (j = 0; j < num * i / 100; j++) {
83 htable_ptrint_add(&ht, int2ptr(j + 2));
84 /* stop it from doubling! */
85 ht.raw.elems = num / 2;
86 }
87 /* Must not have changed! */
88 assert((1 << ht.raw.bits) == num);
89
90 /* Clean cache */
91 count = 0;
92 for (p = htable_ptrint_first(&ht, &it); p; p = htable_ptrint_next(&ht, &it))
93 count++;
94 assert(count == num * i / 100);
95 start = time_now();
96 for (j = 0; j < count; j++)
97 assert(htable_ptrint_get(&ht, j + 2));
98 stop = time_now();
99 avg_run = average_run(&ht, count, &longest_run);
100 printf("%zu,%zu,%zu,%zu,%zu\n",
101 num, count, normalize(&start, &stop, count), avg_run, longest_run);
102 fflush(stdout);
103 htable_ptrint_clear(&ht);
104 }
105
106 return 0;
107}

Callers

nothing calls this directly

Calls 5

errxFunction · 0.85
int2ptrFunction · 0.85
time_nowFunction · 0.85
average_runFunction · 0.85
normalizeFunction · 0.70

Tested by

no test coverage detected