-
Notifications
You must be signed in to change notification settings - Fork 0
/
slow_set.nim
91 lines (82 loc) · 2.43 KB
/
slow_set.nim
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import sets
import times
import random
import intsets
when isMainModule:
var hs1: HashSet[uint64]
var hs2: HashSet[uint64]
var hs3: HashSet[uint64]
var hs4 = initHashSet[uint64](rightSize(100_000))
var hs5 = initHashSet[uint64](rightSize(200_000))
var hs6 = initHashSet[uint64](rightSize(1_100_000))
var hs7: HashSet[uint64]
var hs8 = initIntSet()
# insert 0..200k
var time = cpuTime()
for i in 0..200_000:
let k1 = uint64(i)
hs1.incl(k1)
echo "(1) time ", (cpuTime() - time)
# interleave insert 0..100k and 100k..200k
time = cpuTime()
for i in 0..100_000:
let k1 = uint64(i)
let k2 = uint64(i + 100_000)
hs2.incl(k1)
hs2.incl(k2)
echo "(2) time ", (cpuTime() - time)
# interleave insert 0..100k and 1.0M..1.1M
time = cpuTime()
for i in 0..100_000:
let k1 = uint64(i)
let k2 = uint64(i + 1_000_000)
hs3.incl(k1)
hs3.incl(k2)
echo "(3) time ", (cpuTime() - time)
# interleave insert 0..100k and 1.0M..1.1M
# but insert into a hashSet with space for 100k
time = cpuTime()
for i in 0..100_000:
let k1 = uint64(i)
let k2 = uint64(i + 1_000_000)
hs4.incl(k1)
hs4.incl(k2)
echo "(4) time ", (cpuTime() - time)
# interleave insert 0..100k and 1.0M..1.1M
# but insert into a hashSet with space for 200K
time = cpuTime()
for i in 0..100_000:
let k1 = uint64(i)
let k2 = uint64(i + 1_000_000)
hs5.incl(k1)
hs5.incl(k2)
echo "(5) time ", (cpuTime() - time)
# interleave insert 0..100k and 1.0M..1.1M
# but insert into a hashSet with space for 1.1M
time = cpuTime()
for i in 0..100_000:
let k1 = uint64(i)
let k2 = uint64(i + 1_000_000)
hs6.incl(k1)
hs6.incl(k2)
echo "(6) time ", (cpuTime() - time)
# interleave insert 0..100k and 1M..1.1M in a random order
var vals: seq[int]
for i in 0..100_000:
vals.add(i)
for i in 1_000_000..1_100_000:
vals.add(i)
shuffle(vals)
time = cpuTime()
for i in 0..<len(vals):
let k1 = uint64(vals[i])
hs7.incl(k1)
echo "(7) time ", (cpuTime() - time)
# interleave insert 0..100k and 1.0M..1.1M intset
time = cpuTime()
for i in 0..100_000:
let k1 = i
let k2 = i + 1_000_000
hs8.incl(k1)
hs8.incl(k2)
echo "(8) time ", (cpuTime() - time)