-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmutable.js
42 lines (35 loc) · 891 Bytes
/
mutable.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
const assert = require('uvu/assert');
const { Suite } = require('benchmark');
const contenders = {
'deep-set': require('deep-set'),
'set-value': require('set-value'),
'lodash/set': require('lodash/set'),
'dset': require('../dist').dset,
};
console.log('Validation: ');
Object.keys(contenders).forEach(name => {
try {
const input = {};
contenders[name](input, 'x.y.z', 'foobar');
assert.equal(input, {
x: {
y: {
z: 'foobar'
}
}
});
console.log(' ✔', name);
} catch (err) {
console.log(' ✘', name, `(FAILED)`);
}
});
console.log('\nBenchmark:');
const onCycle = e => console.log(' ' + e.target);
const bench = new Suite({ onCycle });
Object.keys(contenders).forEach(name => {
bench.add(name + ' '.repeat(12 - name.length), () => {
contenders[name]({}, 'x.y.z', 'foobar');
contenders[name]({}, 'x.a.b.c', 'howdy');
});
});
bench.run();