| 125 | } |
| 126 | |
| 127 | int main(int argc, char *argv[]) |
| 128 | { |
| 129 | struct object *objs; |
| 130 | unsigned int i, j; |
| 131 | size_t num, deleted; |
| 132 | struct timeabs start, stop; |
| 133 | struct htable_obj ht; |
| 134 | bool make_dumb = false; |
| 135 | |
| 136 | if (argv[1] && strcmp(argv[1], "--dumb") == 0) { |
| 137 | argv++; |
| 138 | make_dumb = true; |
| 139 | } |
| 140 | num = argv[1] ? atoi(argv[1]) : 1000000; |
| 141 | objs = calloc(num, sizeof(objs[0])); |
| 142 | |
| 143 | for (i = 0; i < num; i++) { |
| 144 | objs[i].key = i; |
| 145 | objs[i].self = &objs[i]; |
| 146 | } |
| 147 | |
| 148 | htable_obj_init(&ht); |
| 149 | |
| 150 | printf("Initial insert: "); |
| 151 | fflush(stdout); |
| 152 | start = time_now(); |
| 153 | for (i = 0; i < num; i++) |
| 154 | htable_obj_add(&ht, objs[i].self); |
| 155 | stop = time_now(); |
| 156 | printf(" %zu ns\n", normalize(&start, &stop, num)); |
| 157 | printf("Details: hash size %u, mask bits %u, perfect %.0f%%\n", |
| 158 | 1U << ht.raw.bits, popcount(ht.raw.common_mask), |
| 159 | perfect(&ht.raw) * 100.0 / ht.raw.elems); |
| 160 | |
| 161 | if (make_dumb) { |
| 162 | /* Screw with mask, to hobble us. */ |
| 163 | update_common(&ht.raw, (void *)~ht.raw.common_bits); |
| 164 | printf("Details: DUMB MODE: mask bits %u\n", |
| 165 | popcount(ht.raw.common_mask)); |
| 166 | } |
| 167 | |
| 168 | printf("Initial lookup (match): "); |
| 169 | fflush(stdout); |
| 170 | start = time_now(); |
| 171 | for (i = 0; i < num; i++) |
| 172 | if (htable_obj_get(&ht, &i)->self != objs[i].self) |
| 173 | abort(); |
| 174 | stop = time_now(); |
| 175 | printf(" %zu ns\n", normalize(&start, &stop, num)); |
| 176 | |
| 177 | printf("Initial lookup (miss): "); |
| 178 | fflush(stdout); |
| 179 | start = time_now(); |
| 180 | for (i = 0; i < num; i++) { |
| 181 | unsigned int n = i + num; |
| 182 | if (htable_obj_get(&ht, &n)) |
| 183 | abort(); |
| 184 | } |
nothing calls this directly
no test coverage detected