mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
627524973a
Aligns the functionality of SlowBuffer with the new Buffer constructor API. Next step is to docs-only deprecate SlowBuffer. Replace the internal uses of SlowBuffer with `Buffer.allocUnsafeSlow(size)` PR-URL: https://github.com/nodejs/node/pull/5833 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
68 lines
1.4 KiB
JavaScript
68 lines
1.4 KiB
JavaScript
'use strict';
|
|
const SlowBuffer = require('buffer').SlowBuffer;
|
|
|
|
const common = require('../common.js');
|
|
const assert = require('assert');
|
|
const bench = common.createBenchmark(main, {
|
|
type: [
|
|
'fast-alloc',
|
|
'fast-alloc-fill',
|
|
'fast-allocUnsafe',
|
|
'slow-allocUnsafe',
|
|
'slow',
|
|
'buffer()'],
|
|
len: [10, 1024, 2048, 4096, 8192],
|
|
n: [1024]
|
|
});
|
|
|
|
function main(conf) {
|
|
const len = +conf.len;
|
|
const n = +conf.n;
|
|
switch (conf.type) {
|
|
case 'fast-alloc':
|
|
bench.start();
|
|
for (let i = 0; i < n * 1024; i++) {
|
|
Buffer.alloc(len);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'fast-alloc-fill':
|
|
bench.start();
|
|
for (let i = 0; i < n * 1024; i++) {
|
|
Buffer.alloc(len, 0);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'fast-allocUnsafe':
|
|
bench.start();
|
|
for (let i = 0; i < n * 1024; i++) {
|
|
Buffer.allocUnsafe(len);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'slow-allocUnsafe':
|
|
bench.start();
|
|
for (let i = 0; i < n * 1024; i++) {
|
|
Buffer.allocUnsafeSlow(len);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'slow':
|
|
bench.start();
|
|
for (let i = 0; i < n * 1024; i++) {
|
|
SlowBuffer(len);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
case 'buffer()':
|
|
bench.start();
|
|
for (let i = 0; i < n * 1024; i++) {
|
|
Buffer(len);
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
default:
|
|
assert.fail(null, null, 'Should not get here');
|
|
}
|
|
}
|