Last active
October 9, 2018 17:44
-
-
Save reconbot/abde2da91a76b6fa94f028db9fd27eab to your computer and use it in GitHub Desktop.
perf test indexof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Benchmark = require('benchmark') | |
const Bl = require('./') | |
const smallBuffers = new Bl(new Array(100).fill(1).map(() => Buffer.alloc(8, 1))) | |
const largeBuffers = new Bl(new Array(100).fill(1).map(() => Buffer.alloc(1024, 1))) | |
const mixedBuffers = new Bl(new Array(100).fill(1).map((val, i) => Buffer.alloc(i ** 2 % 1024, 1))) | |
const veryLargeBuffers = new Bl(new Array(100).fill(1).map(() => Buffer.alloc(1024 * 1024, 1))) | |
const notFindableSmall = Buffer.alloc(7, 0) | |
const notFindableMedium = Buffer.alloc(510, 0) | |
const notFindableLarge = Buffer.alloc(1025, 0) | |
const suite = new Benchmark.Suite() | |
suite.add('smallBuffers small search', () => { | |
smallBuffers.indexOf(notFindableSmall) | |
}) | |
suite.add('smallBuffers medium search', () => { | |
smallBuffers.indexOf(notFindableMedium) | |
}) | |
suite.add('smallBuffers large search', () => { | |
smallBuffers.indexOf(notFindableLarge) | |
}) | |
suite.add('largeBuffers small search', () => { | |
largeBuffers.indexOf(notFindableSmall) | |
}) | |
suite.add('largeBuffers medium search', () => { | |
largeBuffers.indexOf(notFindableMedium) | |
}) | |
suite.add('largeBuffers large search', () => { | |
largeBuffers.indexOf(notFindableLarge) | |
}) | |
suite.add('mixedBuffers small search', () => { | |
mixedBuffers.indexOf(notFindableSmall) | |
}) | |
suite.add('mixedBuffers medium search', () => { | |
mixedBuffers.indexOf(notFindableMedium) | |
}) | |
suite.add('mixedBuffers large search', () => { | |
mixedBuffers.indexOf(notFindableLarge) | |
}) | |
suite.add('veryLargeBuffers small search', () => { | |
veryLargeBuffers.indexOf(notFindableSmall) | |
}) | |
suite.add('veryLargeBuffers medium search', () => { | |
veryLargeBuffers.indexOf(notFindableMedium) | |
}) | |
suite.add('veryLargeBuffers large search', () => { | |
veryLargeBuffers.indexOf(notFindableLarge) | |
}) | |
suite.on('cycle', function(event) { | |
console.log(String(event.target)); | |
}) | |
.on('complete', function() { | |
console.log('done'); | |
}) | |
.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
smallBuffers small search x 2,640,068 ops/sec ±0.45% (91 runs sampled) | |
smallBuffers medium search x 2,519,050 ops/sec ±3.31% (84 runs sampled) | |
smallBuffers large search x 2,694,251 ops/sec ±0.66% (87 runs sampled) | |
largeBuffers small search x 2,621,720 ops/sec ±3.07% (88 runs sampled) | |
largeBuffers medium search x 2,694,856 ops/sec ±0.50% (84 runs sampled) | |
largeBuffers large search x 2,645,516 ops/sec ±2.36% (89 runs sampled) | |
mixedBuffers small search x 2,700,883 ops/sec ±0.40% (87 runs sampled) | |
mixedBuffers medium search x 2,699,650 ops/sec ±0.42% (93 runs sampled) | |
mixedBuffers large search x 2,657,545 ops/sec ±2.67% (85 runs sampled) | |
veryLargeBuffers small search x 2,623,236 ops/sec ±0.66% (89 runs sampled) | |
veryLargeBuffers medium search x 2,605,667 ops/sec ±0.52% (89 runs sampled) | |
veryLargeBuffers large search x 2,611,727 ops/sec ±2.51% (87 runs sampled) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
smallBuffers small search x 2,632,905 ops/sec ±2.51% (87 runs sampled) | |
smallBuffers medium search x 2,486,993 ops/sec ±3.38% (86 runs sampled) | |
smallBuffers large search x 2,663,287 ops/sec ±0.66% (91 runs sampled) | |
largeBuffers small search x 2,639,277 ops/sec ±0.69% (89 runs sampled) | |
largeBuffers medium search x 2,572,525 ops/sec ±2.76% (89 runs sampled) | |
largeBuffers large search x 2,632,493 ops/sec ±0.54% (90 runs sampled) | |
mixedBuffers small search x 2,570,170 ops/sec ±2.55% (88 runs sampled) | |
mixedBuffers medium search x 2,638,102 ops/sec ±0.59% (89 runs sampled) | |
mixedBuffers large search x 2,589,559 ops/sec ±0.74% (91 runs sampled) | |
veryLargeBuffers small search x 2,492,523 ops/sec ±2.30% (91 runs sampled) | |
veryLargeBuffers medium search x 2,651,338 ops/sec ±0.55% (89 runs sampled) | |
veryLargeBuffers large search x 2,597,808 ops/sec ±2.44% (89 runs sampled) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
New working perf test, I was passing arrays of undefined before 😅
// windowing approach
// old approach
The windowing approach is objectively better in pretty much every situation and not significantly worse in other situations