-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.js
56 lines (54 loc) · 1.82 KB
/
bench.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
import Benchmark from 'benchmark';
import { get, compile } from './applicators.js';
import easyobjectselector from 'easy-object-selector';
import objectpath from 'object-path';
import * as dotprop from 'dot-prop';
import * as pathval from 'pathval';
import getvalue from 'get-value';
const selector = 'a.b.c.d';
const compiled = compile(selector);
const obj = { a: { b: { c: { d: 2 } } } }
new Benchmark.Suite('object-selectors vs. easy-object-selector')
.add('object-selectors (string)', function() {
get(selector, obj)
})
.add('object-selectors (pre-compiled)', function() {
get(compiled, obj)
})
.add('object-selectors (pre-compiled, no collation)', function() {
get(compiled, obj, { collate: false })
})
.add('easy-object-selector', function() {
easyobjectselector.select(obj, selector);
})
.add('object-path', function() {
objectpath.get(obj, selector);
})
.add('dot-prop', function() {
dotprop.getProperty(obj, selector);
})
.add('pathval', function() {
pathval.getPathValue(obj, selector);
})
.add('getvalue', function() {
getvalue(obj, selector);
})
.on('cycle', function(event) {
const links = {
'easy-object-selector': 'https://github.com/deltavi/easy-object-selector',
'object-path': 'https://github.com/mariocasciaro/object-path',
'dot-prop': 'https://github.com/sindresorhus/dot-prop',
'pathval': 'https://github.com/chaijs/pathval',
'getvalue': 'https://github.com/jonschlinkert/get-value'
}
// Replace competitors with markdown links
if (event.target.name in links)
event.target.name = `[${event.target.name}](${links[event.target.name]})`;
console.log(String(event.target)
// Replace " x ", if followed immediately by a digit, with " | "
.replace(/ x (?=\d)/, ' | '));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run();