|
1 | 1 | 'use strict'; |
2 | | - |
3 | 2 | const Benchmark = require('benchmark'); |
4 | 3 | const m = require('.'); |
5 | 4 |
|
6 | 5 | const suite = new Benchmark.Suite(); |
7 | 6 |
|
8 | | -suite.add('get', () => { |
9 | | - const f1 = {foo: {bar: 1}}; |
10 | | - m.get(f1); |
11 | | - f1[''] = 'foo'; |
12 | | - m.get(f1, ''); |
13 | | - m.get(f1, 'foo'); |
14 | | - m.get({foo: 1}, 'foo'); |
15 | | - m.get({foo: null}, 'foo'); |
16 | | - m.get({foo: undefined}, 'foo'); |
17 | | - m.get({foo: {bar: true}}, 'foo.bar'); |
18 | | - m.get({foo: {bar: {baz: true}}}, 'foo.bar.baz'); |
19 | | - m.get({foo: {bar: {baz: null}}}, 'foo.bar.baz'); |
20 | | - m.get({foo: {bar: 'a'}}, 'foo.fake'); |
21 | | - m.get({foo: {bar: 'a'}}, 'foo.fake.fake2'); |
22 | | - m.get({'\\': true}, '\\'); |
23 | | - m.get({'\\foo': true}, '\\foo'); |
24 | | - m.get({'bar\\': true}, 'bar\\'); |
25 | | - m.get({'foo\\bar': true}, 'foo\\bar'); |
26 | | - m.get({'\\.foo': true}, '\\\\.foo'); |
27 | | - m.get({'bar\\.': true}, 'bar\\\\.'); |
28 | | - m.get({'foo\\.bar': true}, 'foo\\\\.bar'); |
29 | | - |
30 | | - const f2 = {}; |
31 | | - Object.defineProperty(f2, 'foo', { |
32 | | - value: 'bar', |
33 | | - enumerable: false |
34 | | - }); |
35 | | - m.get(f2, 'foo'); |
36 | | - m.get({}, 'hasOwnProperty'); |
37 | | - |
38 | | - function fn() {} |
39 | | - fn.foo = {bar: 1}; |
40 | | - m.get(fn); |
41 | | - m.get(fn, 'foo'); |
42 | | - m.get(fn, 'foo.bar'); |
43 | | - |
44 | | - const f3 = {foo: null}; |
45 | | - m.get(f3, 'foo.bar'); |
46 | | - |
47 | | - m.get({'foo.baz': {bar: true}}, 'foo\\.baz.bar'); |
48 | | - m.get({'fo.ob.az': {bar: true}}, 'fo\\.ob\\.az.bar'); |
49 | | - |
50 | | - m.get(null, 'foo.bar', false); |
51 | | - m.get('foo', 'foo.bar', false); |
52 | | - m.get([], 'foo.bar', false); |
53 | | - m.get(undefined, 'foo.bar', false); |
54 | | -}) |
| 7 | +suite |
| 8 | + .add('get', () => { |
| 9 | + const f1 = {foo: {bar: 1}}; |
| 10 | + m.get(f1); |
| 11 | + f1[''] = 'foo'; |
| 12 | + m.get(f1, ''); |
| 13 | + m.get(f1, 'foo'); |
| 14 | + m.get({foo: 1}, 'foo'); |
| 15 | + m.get({foo: null}, 'foo'); |
| 16 | + m.get({foo: undefined}, 'foo'); |
| 17 | + m.get({foo: {bar: true}}, 'foo.bar'); |
| 18 | + m.get({foo: {bar: {baz: true}}}, 'foo.bar.baz'); |
| 19 | + m.get({foo: {bar: {baz: null}}}, 'foo.bar.baz'); |
| 20 | + m.get({foo: {bar: 'a'}}, 'foo.fake'); |
| 21 | + m.get({foo: {bar: 'a'}}, 'foo.fake.fake2'); |
| 22 | + m.get({'\\': true}, '\\'); |
| 23 | + m.get({'\\foo': true}, '\\foo'); |
| 24 | + m.get({'bar\\': true}, 'bar\\'); |
| 25 | + m.get({'foo\\bar': true}, 'foo\\bar'); |
| 26 | + m.get({'\\.foo': true}, '\\\\.foo'); |
| 27 | + m.get({'bar\\.': true}, 'bar\\\\.'); |
| 28 | + m.get({'foo\\.bar': true}, 'foo\\\\.bar'); |
| 29 | + |
| 30 | + const f2 = {}; |
| 31 | + Object.defineProperty(f2, 'foo', { |
| 32 | + value: 'bar', |
| 33 | + enumerable: false |
| 34 | + }); |
| 35 | + m.get(f2, 'foo'); |
| 36 | + m.get({}, 'hasOwnProperty'); |
| 37 | + |
| 38 | + function fn() {} |
| 39 | + fn.foo = {bar: 1}; |
| 40 | + m.get(fn); |
| 41 | + m.get(fn, 'foo'); |
| 42 | + m.get(fn, 'foo.bar'); |
| 43 | + |
| 44 | + const f3 = {foo: null}; |
| 45 | + m.get(f3, 'foo.bar'); |
| 46 | + |
| 47 | + m.get({'foo.baz': {bar: true}}, 'foo\\.baz.bar'); |
| 48 | + m.get({'fo.ob.az': {bar: true}}, 'fo\\.ob\\.az.bar'); |
| 49 | + |
| 50 | + m.get(null, 'foo.bar', false); |
| 51 | + m.get('foo', 'foo.bar', false); |
| 52 | + m.get([], 'foo.bar', false); |
| 53 | + m.get(undefined, 'foo.bar', false); |
| 54 | + }) |
55 | 55 | .add('set', () => { |
56 | 56 | const func = () => 'test'; |
57 | 57 | let f1 = {}; |
@@ -156,8 +156,11 @@ suite.add('get', () => { |
156 | 156 |
|
157 | 157 | m.has({'foo.baz': {bar: true}}, 'foo\\.baz.bar'); |
158 | 158 | m.has({'fo.ob.az': {bar: true}}, 'fo\\.ob\\.az.bar'); |
159 | | - }).on('cycle', event => { |
| 159 | + }) |
| 160 | + .on('cycle', event => { |
160 | 161 | console.log(String(event.target)); |
161 | | - }).on('complete', () => { |
| 162 | + }) |
| 163 | + .on('complete', () => { |
162 | 164 | console.log('Finished'); |
163 | | - }).run({async: true}); |
| 165 | + }) |
| 166 | + .run({async: true}); |
0 commit comments