-
Notifications
You must be signed in to change notification settings - Fork 27
/
benchmark.js
56 lines (48 loc) · 1.18 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
var jsonpointer = require('./')
var i
var obj = {
a: 1,
b: {
c: 2
},
d: {
e: [{ a: 3 }, { b: 4 }, { c: 5 }]
}
}
// Get
console.time('get first level property')
for (i = 0; i < 1e6; i++) {
jsonpointer.get(obj, '/a')
}
console.timeEnd('get first level property')
console.time('get second level property')
for (i = 0; i < 1e6; i++) {
jsonpointer.get(obj, '/d/e')
}
console.timeEnd('get second level property')
console.time('get third level property')
for (i = 0; i < 1e6; i++) {
jsonpointer.get(obj, '/d/e/0')
}
console.timeEnd('get third level property')
// Set
console.time('set first level property')
for (i = 0; i < 1e6; i++) {
jsonpointer.set(obj, '/a', 'bla')
}
console.timeEnd('set first level property')
console.time('set second level property')
for (i = 0; i < 1e6; i++) {
jsonpointer.set(obj, '/d/e', 'bla')
}
console.timeEnd('set second level property')
console.time('set third level property')
for (i = 0; i < 1e6; i++) {
jsonpointer.set(obj, '/d/e/0', 'bla')
}
console.timeEnd('set third level property')
console.time('push property into array')
for (i = 0; i < 1e6; i++) {
jsonpointer.set(obj, '/d/e/-', 'bla')
}
console.timeEnd('push property into array')