MCPcopy Create free account
hub / github.com/git/git / perf_hashmap

Function perf_hashmap

t/helper/test-hashmap.c:83–132  ·  view source on GitHub ↗

* Test performance of hashmap.[ch] * Usage: time echo "perfhashmap method rounds" | test-tool hashmap */

Source from the content-addressed store, hash-verified

81 * Usage: time echo "perfhashmap method rounds" | test-tool hashmap
82 */
83static void perf_hashmap(unsigned int method, unsigned int rounds)
84{
85 struct hashmap map;
86 char buf[16];
87 struct test_entry **entries;
88 unsigned int *hashes;
89 unsigned int i, j;
90
91 ALLOC_ARRAY(entries, TEST_SIZE);
92 ALLOC_ARRAY(hashes, TEST_SIZE);
93 for (i = 0; i < TEST_SIZE; i++) {
94 xsnprintf(buf, sizeof(buf), "%i", i);
95 entries[i] = alloc_test_entry(0, buf, "");
96 hashes[i] = hash(method, i, entries[i]->key);
97 }
98
99 if (method & TEST_ADD) {
100 /* test adding to the map */
101 for (j = 0; j < rounds; j++) {
102 hashmap_init(&map, test_entry_cmp, NULL, 0);
103
104 /* add entries */
105 for (i = 0; i < TEST_SIZE; i++) {
106 hashmap_entry_init(&entries[i]->ent, hashes[i]);
107 hashmap_add(&map, &entries[i]->ent);
108 }
109
110 hashmap_clear(&map);
111 }
112 } else {
113 /* test map lookups */
114 hashmap_init(&map, test_entry_cmp, NULL, 0);
115
116 /* fill the map (sparsely if specified) */
117 j = (method & TEST_SPARSE) ? TEST_SIZE / 10 : TEST_SIZE;
118 for (i = 0; i < j; i++) {
119 hashmap_entry_init(&entries[i]->ent, hashes[i]);
120 hashmap_add(&map, &entries[i]->ent);
121 }
122
123 for (j = 0; j < rounds; j++) {
124 for (i = 0; i < TEST_SIZE; i++) {
125 hashmap_get_from_hash(&map, hashes[i],
126 entries[i]->key);
127 }
128 }
129
130 hashmap_clear(&map);
131 }
132}
133
134#define DELIM " \t\r\n"
135

Callers 1

cmd__hashmapFunction · 0.85

Calls 7

xsnprintfFunction · 0.85
hashFunction · 0.85
hashmap_initFunction · 0.85
hashmap_entry_initFunction · 0.85
hashmap_addFunction · 0.85
hashmap_get_from_hashFunction · 0.85
alloc_test_entryFunction · 0.70

Tested by

no test coverage detected