forked from jaredLunde/masonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
44 lines (37 loc) · 1.01 KB
/
index.ts
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
import bench from '@essentials/benchmark'
import randInt from 'rand-int'
import createIntervalTree from '../src/IntervalTree'
bench('IntervalTree.search()', ({duration}) => {
duration(4000)
const tree = createIntervalTree()
for (let i = 0; i < 5000; i++) {
const lower = randInt(0, 200000)
tree.insert(lower, lower + randInt(200, 400), i)
}
const cb = () => {}
return () => {
tree.search(0, 300000, cb)
}
})
bench('IntervalTree.insert()', ({duration}) => {
duration(4000)
const tree = createIntervalTree()
let i = 0
return () => {
tree.insert(randInt(0, 200000), randInt(200001, 40000000), i++)
}
})
bench('IntervalTree.remove()', ({duration}) => {
duration(4000)
const intervals: number[][] = []
const tree = createIntervalTree()
let i = 0
for (; i < 5000000; i++) {
const interval = [randInt(0, 200000), randInt(200001, 40000000), i]
intervals.push(interval)
tree.insert.apply(null, interval)
}
return () => {
tree.remove.apply(null, intervals[--i])
}
})