- copyBytesFrom: calculate byte offsets directly instead of
slicing into an intermediate typed array
- toString('hex'): use V8 Uint8Array.prototype.toHex() builtin
- fill: add single-char ASCII fast path
- indexOf: use indexOfString directly for ASCII encoding
- swap16/32/64: add V8 Fast API functions
PR-URL: https://github.com/nodejs/node/pull/61871
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
31 lines
727 B
JavaScript
31 lines
727 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
type: ['Uint8Array', 'Uint16Array', 'Uint32Array', 'Float64Array'],
|
|
len: [64, 256, 2048],
|
|
partial: ['none', 'offset', 'offset-length'],
|
|
n: [6e5],
|
|
});
|
|
|
|
function main({ n, len, type, partial }) {
|
|
const TypedArrayCtor = globalThis[type];
|
|
const src = new TypedArrayCtor(len);
|
|
for (let i = 0; i < len; i++) src[i] = i;
|
|
|
|
let offset;
|
|
let length;
|
|
if (partial === 'offset') {
|
|
offset = len >>> 2;
|
|
} else if (partial === 'offset-length') {
|
|
offset = len >>> 2;
|
|
length = len >>> 1;
|
|
}
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
Buffer.copyBytesFrom(src, offset, length);
|
|
}
|
|
bench.end(n);
|
|
}
|