-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.js
140 lines (100 loc) · 3.26 KB
/
benchmark.js
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'use strict'
const Benchmark = require('benchmark')
const suite = new Benchmark.Suite()
const nodups = require('./')
const uniq = require('uniq')
const _uniq = require('lodash.uniq')
const _uniqWith = require('lodash.uniqwith')
const arrayUniq = require('array-uniq')
const arrayUnique = require('array-uniq')
const uniqs = require('uniqs')
const dedupe = require('dedupe')
console.log(uniq([5, 1, 1, 2, 3, 4, 2, 3, 5, 1]))
console.log(_uniq([5, 1, 1, 2, 3, 4, 2, 3, 5, 1]))
console.log(_uniq([5, 1, 1, 2, 3, 4, 2, 3, 5, 1]))
console.log(_uniqWith([5, 1, 1, 2, 3, 4, 2, 3, 5, 1], (a, b) => a === b))
console.log(arrayUniq([5, 1, 1, 2, 3, 4, 2, 3, 5, 1]))
console.log(uniqs([5, 1, 1, 2, 3, 4, 2, 3, 5, 1]))
console.log(nodups([5, 1, 1, 2, 3, 4, 2, 3, 5, 1]))
console.log(arrayUnique([5, 1, 1, 2, 3, 4, 2, 3, 5, 1]))
console.log(dedupe([5, 1, 1, 2, 3, 4, 2, 3, 5, 1]))
suite
.add('uniq', function() {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
uniq(arr)
})
.add('lodash.uniq', function() {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
_uniq(arr)
})
.add('lodash.uniqWith', function() {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
_uniqWith(arr, (a, b) => a === b)
})
.add('arrayUniq', function() {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
arrayUniq(arr)
})
.add('arrayUnique', function() {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
arrayUnique(arr)
})
.add('uniqs', function() {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
uniqs(arr)
})
.add('dedupe', function() {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
dedupe(arr)
})
.add('nodups', function() {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
nodups(arr)
})
.add('nodups {sorted}', function () {
var arr = [1, 1, 1, 2, 2, 3, 3, 4, 5, 5]
nodups(arr, {sorted: true})
})
.add('nodups {inplace}', function () {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
nodups(arr, {inplace: true})
})
.add('nodups {compare ==}', function () {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
nodups(arr, {compare: '=='})
})
.add('nodups {compare ===}', function () {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
nodups(arr, {compare: '==='})
})
.add('nodups {compare fn()}', function () {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
nodups(arr, { compare: (a, b) => a === b })
})
.add('nodups {strict false}', function () {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
nodups(arr, { strict: false })
})
.add('nodups {onUnique}', function () {
var arr = [5, 1, 1, 2, 3, 4, 2, 3, 5, 1]
nodups(arr, { onUnique: () => {} })
})
.add('nodups {by}', function () {
var arr = [{ a: 1, b: 2 }, { a: 1, b: 2 }, { a: 2, b: 2 }, { a: 2, b: 2 }, { a: 3, b: 2 }, { a: 5, b: 2 }]
nodups(arr, { by: 'a' })
})
.add('nodups {skip}', function () {
var arr = [{ a: 1, b: 2 }, { a: 1, b: 2 }, { a: 2, b: 2 }, { a: 2, b: 2 }, { a: 3, b: 2 }, { a: 5, b: 2 }]
nodups(arr, { skip: 'b' })
})
.add('lodash.uniqWith', function() {
var arr = [{ a: 1, b: 2 }, { a: 1, b: 2 }, { a: 2, b: 2 }, { a: 2, b: 2 }, { a: 3, b: 2 }, { a: 5, b: 2 }]
_uniqWith(arr, function (a, b) { return a.a === b.a })
})
.on('cycle', function(event) {
console.log(String(event.target))
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'))
})
.run({ 'async': true })