Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
benchmark: refactor buffer benchmarks#26418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,8 +2,8 @@ | ||
| const common = require('../common.js'); | ||
| const bench = common.createBenchmark(main, { | ||
| size: [16, 512, 1024, 4096, 16386], | ||
| args: [1, 2, 3, 4, 5], | ||
| size: [16, 512, 4096, 16386], | ||
| args: [1, 2, 5], | ||
BridgeAR marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| n: [1e6] | ||
| }); | ||
| @@ -16,22 +16,6 @@ function main({ n, size, args }) { | ||
| b1[size - 1] = 'b'.charCodeAt(0); | ||
| switch (args) { | ||
| case 2: | ||
| b0.compare(b1, 0); | ||
| break; | ||
| case 3: | ||
| b0.compare(b1, 0, b1Len); | ||
| break; | ||
| case 4: | ||
| b0.compare(b1, 0, b1Len, 0); | ||
| break; | ||
| case 5: | ||
| b0.compare(b1, 0, b1Len, 0, b0Len); | ||
| break; | ||
| default: | ||
| b0.compare(b1); | ||
| } | ||
BridgeAR marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| switch (args) { | ||
| case 2: | ||
| b0.compare(b1, 0); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,20 +2,20 @@ | ||
| const common = require('../common.js'); | ||
| const bench = common.createBenchmark(main, { | ||
| pieces: [1, 4, 16], | ||
| pieces: [4, 16], | ||
| pieceSize: [1, 16, 256], | ||
| withTotalLength: [0, 1], | ||
| n: [1024] | ||
| n: [8e5] | ||
BridgeAR marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }); | ||
| function main({ n, pieces, pieceSize, withTotalLength }) { | ||
| const list = new Array(pieces); | ||
| list.fill(Buffer.allocUnsafe(pieceSize)); | ||
| const list = Array.from({ length: pieces }) | ||
BridgeAR marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| .fill(Buffer.allocUnsafe(pieceSize)); | ||
| const totalLength = withTotalLength ? pieces * pieceSize : undefined; | ||
| bench.start(); | ||
| for (var i = 0; i < n * 1024; i++) { | ||
| for (var i = 0; i < n; i++) { | ||
| Buffer.concat(list, totalLength); | ||
| } | ||
| bench.end(n); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| 'use strict'; | ||
| const SlowBuffer = require('buffer').SlowBuffer; | ||
| const common = require('../common.js'); | ||
| const assert = require('assert'); | ||
| @@ -9,10 +8,9 @@ const bench = common.createBenchmark(main, { | ||
| 'fast-alloc-fill', | ||
| 'fast-allocUnsafe', | ||
| 'slow-allocUnsafe', | ||
| 'slow', | ||
| 'buffer()'], | ||
| len: [10, 1024, 2048, 4096, 8192], | ||
| n: [1024] | ||
| ], | ||
| len: [10, 1024, 4096, 8192], | ||
| n: [6e5] | ||
BridgeAR marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }); | ||
| function main({ len, n, type }) { | ||
| @@ -24,7 +22,7 @@ function main({ len, n, type }) { | ||
| break; | ||
| case 'fast-alloc-fill': | ||
| bench.start(); | ||
| for (i = 0; i < n * 1024; i++) { | ||
| for (i = 0; i < n; i++) { | ||
| Buffer.alloc(len, 0); | ||
| } | ||
| bench.end(n); | ||
| @@ -35,18 +33,12 @@ function main({ len, n, type }) { | ||
| case 'slow-allocUnsafe': | ||
| fn = Buffer.allocUnsafeSlow; | ||
| break; | ||
| case 'slow': | ||
| fn = SlowBuffer; | ||
| break; | ||
| case 'buffer()': | ||
| fn = Buffer; | ||
| break; | ||
| default: | ||
| assert.fail('Should not get here'); | ||
| } | ||
| bench.start(); | ||
| for (i = 0; i < n * 1024; i++) { | ||
| for (i = 0; i < n; i++) { | ||
| fn(len); | ||
| } | ||
| bench.end(n); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -8,14 +8,13 @@ const bench = common.createBenchmark(main, { | ||
| 'arraybuffer', | ||
| 'arraybuffer-middle', | ||
| 'buffer', | ||
| 'uint8array', | ||
| 'string', | ||
| 'string-utf8', | ||
| 'string-base64', | ||
| 'object', | ||
| ], | ||
| len: [10, 2048], | ||
| n: [2048] | ||
| len: [100, 2048], | ||
| n: [8e5] | ||
BridgeAR marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }); | ||
| function main({ len, n, source }) { | ||
| @@ -26,17 +25,19 @@ function main({ len, n, source }) { | ||
| const uint8array = new Uint8Array(len); | ||
| const obj = { length: null }; // Results in a new, empty Buffer | ||
| let i = 0; | ||
| switch (source) { | ||
| case 'array': | ||
| bench.start(); | ||
| for (let i = 0; i < n * 1024; i++) { | ||
| for (i = 0; i < n; i++) { | ||
| Buffer.from(array); | ||
| } | ||
| bench.end(n); | ||
| break; | ||
| case 'arraybuffer': | ||
| bench.start(); | ||
| for (let i = 0; i < n * 1024; i++) { | ||
| for (i = 0; i < n; i++) { | ||
| Buffer.from(arrayBuf); | ||
| } | ||
| bench.end(n); | ||
| @@ -45,49 +46,49 @@ function main({ len, n, source }) { | ||
| const offset = ~~(len / 4); | ||
| const length = ~~(len / 2); | ||
| bench.start(); | ||
| for (let i = 0; i < n * 1024; i++) { | ||
| for (i = 0; i < n; i++) { | ||
| Buffer.from(arrayBuf, offset, length); | ||
| } | ||
| bench.end(n); | ||
| break; | ||
| case 'buffer': | ||
| bench.start(); | ||
| for (let i = 0; i < n * 1024; i++) { | ||
| for (i = 0; i < n; i++) { | ||
| Buffer.from(buffer); | ||
| } | ||
| bench.end(n); | ||
| break; | ||
| case 'uint8array': | ||
| bench.start(); | ||
| for (let i = 0; i < n * 1024; i++) { | ||
| for (i = 0; i < n; i++) { | ||
| Buffer.from(uint8array); | ||
| } | ||
| bench.end(n); | ||
| break; | ||
| case 'string': | ||
| bench.start(); | ||
| for (let i = 0; i < n * 1024; i++) { | ||
| for (i = 0; i < n; i++) { | ||
| Buffer.from(str); | ||
| } | ||
| bench.end(n); | ||
| break; | ||
| case 'string-utf8': | ||
| bench.start(); | ||
| for (let i = 0; i < n * 1024; i++) { | ||
| for (i = 0; i < n; i++) { | ||
| Buffer.from(str, 'utf8'); | ||
| } | ||
| bench.end(n); | ||
| break; | ||
| case 'string-base64': | ||
| bench.start(); | ||
| for (let i = 0; i < n * 1024; i++) { | ||
| for (i = 0; i < n; i++) { | ||
| Buffer.from(str, 'base64'); | ||
| } | ||
| bench.end(n); | ||
| break; | ||
| case 'object': | ||
| bench.start(); | ||
| for (let i = 0; i < n * 1024; i++) { | ||
| for (i = 0; i < n; i++) { | ||
| Buffer.from(obj); | ||
| } | ||
| bench.end(n); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,8 +3,8 @@ | ||
| const common = require('../common.js'); | ||
| const bench = common.createBenchmark(main, { | ||
| len: [0, 1, 64, 1024], | ||
| n: [1e7] | ||
| len: [64, 1024], | ||
| n: [1e6] | ||
BridgeAR marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }); | ||
| function main({ len, n }) { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,26 +6,22 @@ const path = require('path'); | ||
| const searchStrings = [ | ||
| '@', | ||
| 'SQ', | ||
| '10x', | ||
| '--l', | ||
| 'Alice', | ||
| 'Gryphon', | ||
| 'Panther', | ||
| 'Ou est ma chatte?', | ||
| 'found it very', | ||
| 'among mad people', | ||
| 'neighbouring pool', | ||
| 'Soo--oop', | ||
| 'aaaaaaaaaaaaaaaaa', | ||
| 'venture to go near the house till she had brought herself down to', | ||
| '</i> to the Caterpillar', | ||
| ]; | ||
| const bench = common.createBenchmark(main, { | ||
| search: searchStrings, | ||
| encoding: ['undefined', 'utf8', 'ucs2', 'binary'], | ||
| encoding: ['utf8', 'ucs2'], | ||
| type: ['buffer', 'string'], | ||
| n: [100000] | ||
| n: [5e4] | ||
BridgeAR marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }); | ||
| function main({ n, search, encoding, type }) { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,8 +4,8 @@ const common = require('../common.js'); | ||
| const assert = require('assert'); | ||
| const bench = common.createBenchmark(main, { | ||
| size: [16, 512, 1024, 4096, 16386], | ||
| type: ['fast', 'slow'], | ||
| size: [512, 4096, 16386], | ||
| type: ['fast'], | ||
BridgeAR marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| method: ['for', 'forOf', 'iterator'], | ||
| n: [1e3] | ||
| }); | ||
| @@ -17,9 +17,10 @@ const methods = { | ||
| }; | ||
| function main({ size, type, method, n }) { | ||
| const clazz = type === 'fast' ? Buffer : SlowBuffer; | ||
| const buffer = new clazz(size); | ||
| buffer.fill(0); | ||
| const buffer = type === 'fast' ? | ||
| Buffer.alloc(size) : | ||
| SlowBuffer(size).fill(0); | ||
| const fn = methods[method || 'for']; | ||
| bench.start(); | ||
| @@ -46,7 +47,7 @@ function benchForOf(buffer, n) { | ||
| function benchIterator(buffer, n) { | ||
| for (var k = 0; k < n; k++) { | ||
| const iter = buffer[Symbol.iterator](); | ||
| var cur = iter.next(); | ||
| let cur = iter.next(); | ||
| while (!cur.done) { | ||
| assert(cur.value === 0); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,23 +5,18 @@ const common = require('../common.js'); | ||
| const bench = common.createBenchmark(main, { | ||
| encoding: [ | ||
| 'ascii', | ||
| 'ASCII', | ||
| 'base64', | ||
| 'BASE64', | ||
| 'binary', | ||
| 'BINARY', | ||
| 'hex', | ||
| 'HEX', | ||
| 'latin1', | ||
| 'LATIN1', | ||
| 'ucs-2', | ||
| 'UCS-2', | ||
| 'ucs2', | ||
| 'UCS2', | ||
| 'utf-16le', | ||
| 'UTF-16LE', | ||
| 'utf-8', | ||
| 'UTF-8', | ||
| 'utf16le', | ||
BridgeAR marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| 'UTF16LE', | ||
| 'utf8', | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,7 +3,7 @@ const common = require('../common.js'); | ||
| const bench = common.createBenchmark(main, { | ||
| type: ['Double', 'Float'], | ||
| endian: ['BE', 'LE'], | ||
| endian: ['LE'], | ||
BridgeAR marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| value: ['zero', 'big', 'small', 'inf', 'nan'], | ||
| n: [1e6] | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,15 +9,16 @@ const types = [ | ||
| ]; | ||
| const bench = common.createBenchmark(main, { | ||
| buffer: ['fast', 'slow'], | ||
| buffer: ['fast'], | ||
BridgeAR marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| type: types, | ||
| n: [1e6], | ||
| byteLength: [1, 2, 3, 4, 5, 6] | ||
| }); | ||
| function main({ n, buf, type, byteLength }) { | ||
| const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer; | ||
| const buff = new clazz(8); | ||
| const buff = buf === 'fast' ? | ||
| Buffer.alloc(8) : | ||
| require('buffer').SlowBuffer(8); | ||
| const fn = `read${type || 'IntBE'}`; | ||
| buff.writeDoubleLE(0, 0); | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.