aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benchmark/buffers/buffer-read-with-byteLength.js34
-rw-r--r--benchmark/buffers/buffer-read.js22
-rw-r--r--test/sequential/test-benchmark-buffer.js3
3 files changed, 43 insertions, 16 deletions
diff --git a/benchmark/buffers/buffer-read-with-byteLength.js b/benchmark/buffers/buffer-read-with-byteLength.js
new file mode 100644
index 0000000000..013947da9d
--- /dev/null
+++ b/benchmark/buffers/buffer-read-with-byteLength.js
@@ -0,0 +1,34 @@
+'use strict';
+const common = require('../common.js');
+
+const types = [
+ 'IntLE',
+ 'IntBE',
+];
+
+const bench = common.createBenchmark(main, {
+ noAssert: ['false', 'true'],
+ buffer: ['fast', 'slow'],
+ type: types,
+ millions: [1],
+ byteLength: [1, 2, 4, 6]
+});
+
+function main(conf) {
+ const noAssert = conf.noAssert === 'true';
+ const len = conf.millions * 1e6;
+ const clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
+ const buff = new clazz(8);
+ const type = conf.type || 'UInt8';
+ const fn = `read${type}`;
+
+ buff.writeDoubleLE(0, 0, noAssert);
+ const testFunction = new Function('buff', `
+ for (var i = 0; i !== ${len}; i++) {
+ buff.${fn}(0, ${conf.byteLength}, ${JSON.stringify(noAssert)});
+ }
+ `);
+ bench.start();
+ testFunction(buff);
+ bench.end(len / 1e6);
+}
diff --git a/benchmark/buffers/buffer-read.js b/benchmark/buffers/buffer-read.js
index 22f8dcbd3d..339da75bef 100644
--- a/benchmark/buffers/buffer-read.js
+++ b/benchmark/buffers/buffer-read.js
@@ -15,9 +15,7 @@ const types = [
'FloatLE',
'FloatBE',
'DoubleLE',
- 'DoubleBE',
- 'IntLE',
- 'IntBE',
+ 'DoubleBE'
];
const bench = common.createBenchmark(main, {
@@ -36,19 +34,11 @@ function main(conf) {
const fn = `read${type}`;
buff.writeDoubleLE(0, 0, noAssert);
-
- var call;
- if (fn === 'readIntLE' || fn === 'readIntBE') {
- call = `buff.${fn}(0, 1, ${JSON.stringify(noAssert)})`;
- } else {
- call = `buff.${fn}(0, ${JSON.stringify(noAssert)})`;
- }
-
- const testFunction = new Function(
- 'buff',
- `for (var i = 0; i !== ${len}; ++i) { ${call}; }`
- );
-
+ const testFunction = new Function('buff', `
+ for (var i = 0; i !== ${len}; i++) {
+ buff.${fn}(0, ${JSON.stringify(noAssert)});
+ }
+ `);
bench.start();
testFunction(buff);
bench.end(len / 1e6);
diff --git a/test/sequential/test-benchmark-buffer.js b/test/sequential/test-benchmark-buffer.js
index 26600cf4f2..2cee628ada 100644
--- a/test/sequential/test-benchmark-buffer.js
+++ b/test/sequential/test-benchmark-buffer.js
@@ -9,7 +9,9 @@ runBenchmark('buffers',
'aligned=true',
'args=1',
'buffer=fast',
+ 'byteLength=1',
'encoding=utf8',
+ 'endian=BE',
'len=2',
'method=',
'n=1',
@@ -20,6 +22,7 @@ runBenchmark('buffers',
'size=1',
'source=array',
'type=',
+ 'value=0',
'withTotalLength=0'
],
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });