-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunique.benchmark.ts
57 lines (45 loc) · 1.14 KB
/
unique.benchmark.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
45
46
47
48
49
50
51
52
53
54
55
56
57
import lodash from 'lodash'
import { Benchmark } from '../benchmarkHelper'
import { unique } from './unique'
function generateArrayOfSize(size: number): Array<number> {
const array: Array<number> = []
for (let i = 0; i !== size; i++) {
array.push(Math.random())
}
return array
}
const LARGE_ARRAY = generateArrayOfSize(10000)
const SMALL_ARRAY = generateArrayOfSize(100)
console.log('Setup finished')
const benchmark = new Benchmark('unique')
benchmark.add({
library: 'es6 filter',
input: 'large array',
func: () => LARGE_ARRAY.filter((x, i, self) => self.indexOf(x) === i),
})
benchmark.add({
library: 'es6 filter',
input: 'small array',
func: () => SMALL_ARRAY.filter((x, i, self) => self.indexOf(x) === i),
})
benchmark.add({
library: 'lodash',
input: 'large array',
func: () => lodash.uniq(LARGE_ARRAY),
})
benchmark.add({
library: 'lodash',
input: 'small array',
func: () => lodash.uniq(SMALL_ARRAY),
})
benchmark.add({
library: 'flocky',
input: 'large array',
func: () => unique(LARGE_ARRAY),
})
benchmark.add({
library: 'flocky',
input: 'small array',
func: () => unique(SMALL_ARRAY),
})
benchmark.run()