Icard/angular-clarity-master(work.../node_modules/object-path/benchmark.js

53 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2024-07-16 14:55:36 +00:00
var Benchpress = require('@mariocasciaro/benchpress')
var benchmark = new Benchpress()
var op = require('./')
var testObj = {
level1_a: {
level2_a: {
level3_a: {
level4_a: {
}
}
}
}
}
var testObj2
benchmark
.add('get existing', {
iterations: 100000,
fn: function() {
op.get(testObj, ['level1_a', 'level2_a', 'level3_a', 'level4_a'])
}
})
.add('get non-existing', {
iterations: 100000,
fn: function() {
op.get(testObj, ['level5_a'])
}
})
.add('push', {
iterations: 100000,
fn: function() {
op.push(testObj, ['level1_a', 'level2_a', 'level3_a', 'level4_a', 'level5_a'], 'val')
}
})
.add('set non existing', {
iterations: 100000,
fn: function() {
op.set(testObj2, ['level1_a', 'level2_b', 'level3_b', 'level4_b', 'level5_b'], 'val')
},
beforeEach: function() {
testObj2 = {}
}
})
.add('set existing', {
iterations: 100000,
fn: function() {
op.set(testObj, ['level1_a', 'level2_a', 'level3_a', 'level4_a', 'level5_b'], 'val')
}
})
.run()