-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: split
Buffer.byteLength
benchmark
PR-URL: #46616 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
f558797
commit 04166fe
Showing
3 changed files
with
62 additions
and
49 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
len: [2, 16, 256], // x16 | ||
n: [4e6], | ||
}); | ||
|
||
function main({ n, len }) { | ||
const data = Buffer.alloc(len * 16, 'a'); | ||
const expected = Buffer.byteLength(data, 'buffer'); | ||
let changed = false; | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
const actual = Buffer.byteLength(data, 'buffer'); | ||
if (expected !== actual) { changed = true; } | ||
} | ||
bench.end(n); | ||
if (changed) { | ||
throw new Error('Result changed during iteration'); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: ['one_byte', 'two_bytes', 'three_bytes', 'four_bytes'], | ||
encoding: ['utf8', 'base64'], | ||
repeat: [1, 2, 16, 256], // x16 | ||
n: [4e6], | ||
}); | ||
|
||
// 16 chars each | ||
const chars = { | ||
one_byte: 'hello brendan!!!', | ||
two_bytes: 'ΰαβγδεζηθικλμνξο', | ||
three_bytes: '挰挱挲挳挴挵挶挷挸挹挺挻挼挽挾挿', | ||
four_bytes: '𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢', | ||
}; | ||
|
||
function getInput(type, repeat, encoding) { | ||
const original = (repeat === 1) ? chars[type] : chars[type].repeat(repeat); | ||
if (encoding === 'base64') { | ||
Buffer.from(original, 'utf8').toString('base64'); | ||
} | ||
return original; | ||
} | ||
|
||
function main({ n, repeat, encoding, type }) { | ||
const data = getInput(type, repeat, encoding); | ||
const expected = Buffer.byteLength(data, encoding); | ||
let changed = false; | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
const actual = Buffer.byteLength(data, encoding); | ||
if (expected !== actual) { changed = true; } | ||
} | ||
bench.end(n); | ||
if (changed) { | ||
throw new Error('Result changed during iteration'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.