1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#include <stdio.h>
#include <time.h>
#include <stc/crandom.h>
#include <stc/cmap.h>
#include <stc/cvec.h>
#include <stc/cstr.h>
using_cmap(ic, uint64_t, uint8_t);
const static uint64_t seed = 1234;
const static uint64_t N = 1ull << 27;
const static uint64_t mask = (1ull << 52) - 1;
void repeats(void)
{
crand_rng64_t rng = crand_rng64_init(seed);
cmap_ic m = cmap_INIT;
cmap_ic_reserve(&m, N);
clock_t now = clock();
for (size_t i = 0; i < N; ++i) {
uint64_t k = crand_i64(&rng) & mask;
int v = ++cmap_ic_emplace(&m, k, 0).first->second;
if (v > 1) printf("%zu: %llx - %d\n", i, k, v);
}
float diff = (float) (clock() - now) / CLOCKS_PER_SEC;
printf("%.02f", diff);
}
using_cmap(x, uint32_t, uint64_t);
using_cvec(x, uint64_t);
void distribution(void)
{
crand_rng32_t rng = crand_rng32_init(seed); // time(NULL), time(NULL));
const size_t N = 1ull << 28, M = 1ull << 9; // 1ull << 10;
cmap_x map = cmap_x_with_capacity(M);
clock_t now = clock();
crand_uniform_i32_t dist = crand_uniform_i32_init(0, M);
for (size_t i = 0; i < N; ++i) {
++cmap_x_emplace(&map, crand_uniform_i32(&rng, &dist), 0).first->second;
}
float diff = (float) (clock() - now) / CLOCKS_PER_SEC;
uint64_t sum = 0;
c_foreach (i, cmap_x, map) sum += i.get->second;
sum /= map.size;
c_foreach (i, cmap_x, map)
printf("%u: %zu - %zu\n", i.get->first, i.get->second, sum);
printf("%.02f\n", diff);
}
int main()
{
repeats();
//distribution();
}
|