Skip to content

Commit

Permalink
benchmark: changed millions and thousands to n
Browse files Browse the repository at this point in the history
PR-URL: #18917
Fixes: #18778
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: Andreas Madsen <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
  • Loading branch information
juggernaut451 authored and BridgeAR committed Apr 9, 2018
1 parent 28e5c46 commit b80da63
Show file tree
Hide file tree
Showing 46 changed files with 277 additions and 309 deletions.
25 changes: 12 additions & 13 deletions benchmark/buffers/buffer-compare-instance-method.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ const common = require('../common.js');
const bench = common.createBenchmark(main, {
size: [16, 512, 1024, 4096, 16386],
args: [1, 2, 3, 4, 5],
millions: [1]
n: [1e6]
});

function main({ millions, size, args }) {
const iter = millions * 1e6;
function main({ n, size, args }) {
const b0 = Buffer.alloc(size, 'a');
const b1 = Buffer.alloc(size, 'a');
const b0Len = b0.length;
Expand Down Expand Up @@ -37,41 +36,41 @@ function main({ millions, size, args }) {
case 2:
b0.compare(b1, 0);
bench.start();
for (i = 0; i < iter; i++) {
for (i = 0; i < n; i++) {
b0.compare(b1, 0);
}
bench.end(iter / 1e6);
bench.end(n);
break;
case 3:
b0.compare(b1, 0, b1Len);
bench.start();
for (i = 0; i < iter; i++) {
for (i = 0; i < n; i++) {
b0.compare(b1, 0, b1Len);
}
bench.end(iter / 1e6);
bench.end(n);
break;
case 4:
b0.compare(b1, 0, b1Len, 0);
bench.start();
for (i = 0; i < iter; i++) {
for (i = 0; i < n; i++) {
b0.compare(b1, 0, b1Len, 0);
}
bench.end(iter / 1e6);
bench.end(n);
break;
case 5:
b0.compare(b1, 0, b1Len, 0, b0Len);
bench.start();
for (i = 0; i < iter; i++) {
for (i = 0; i < n; i++) {
b0.compare(b1, 0, b1Len, 0, b0Len);
}
bench.end(iter / 1e6);
bench.end(n);
break;
default:
b0.compare(b1);
bench.start();
for (i = 0; i < iter; i++) {
for (i = 0; i < n; i++) {
b0.compare(b1);
}
bench.end(iter / 1e6);
bench.end(n);
}
}
9 changes: 4 additions & 5 deletions benchmark/buffers/buffer-compare-offset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const common = require('../common.js');
const bench = common.createBenchmark(main, {
method: ['offset', 'slice'],
size: [16, 512, 1024, 4096, 16386],
millions: [1]
n: [1e6]
});

function compareUsingSlice(b0, b1, len, iter) {
Expand All @@ -17,13 +17,12 @@ function compareUsingOffset(b0, b1, len, iter) {
b0.compare(b1, 1, len, 1, len);
}

function main({ millions, size, method }) {
const iter = millions * 1e6;
function main({ n, size, method }) {
const fn = method === 'slice' ? compareUsingSlice : compareUsingOffset;
bench.start();
fn(Buffer.alloc(size, 'a'),
Buffer.alloc(size, 'b'),
size >> 1,
iter);
bench.end(millions);
n);
bench.end(n);
}
9 changes: 4 additions & 5 deletions benchmark/buffers/buffer-compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@ const common = require('../common.js');

const bench = common.createBenchmark(main, {
size: [16, 512, 1024, 4096, 16386],
millions: [1]
n: [1e6]
});

function main({ millions, size }) {
const iter = millions * 1e6;
function main({ n, size }) {
const b0 = Buffer.alloc(size, 'a');
const b1 = Buffer.alloc(size, 'a');

b1[size - 1] = 'b'.charCodeAt(0);

bench.start();
for (var i = 0; i < iter; i++) {
for (var i = 0; i < n; i++) {
Buffer.compare(b0, b1);
}
bench.end(iter / 1e6);
bench.end(n);
}
8 changes: 4 additions & 4 deletions benchmark/buffers/buffer-read-float.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const bench = common.createBenchmark(main, {
type: ['Double', 'Float'],
endian: ['BE', 'LE'],
value: ['zero', 'big', 'small', 'inf', 'nan'],
millions: [1]
n: [1e6]
});

function main({ millions, type, endian, value }) {
function main({ n, type, endian, value }) {
type = type || 'Double';
const buff = Buffer.alloc(8);
const fn = `read${type}${endian}`;
Expand All @@ -32,8 +32,8 @@ function main({ millions, type, endian, value }) {
buff[`write${type}${endian}`](values[type][value], 0);

bench.start();
for (var i = 0; i !== millions * 1e6; i++) {
for (var i = 0; i !== n; i++) {
buff[fn](0);
}
bench.end(millions);
bench.end(n);
}
8 changes: 4 additions & 4 deletions benchmark/buffers/buffer-read-with-byteLength.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ const types = [
const bench = common.createBenchmark(main, {
buffer: ['fast', 'slow'],
type: types,
millions: [1],
n: [1e6],
byteLength: [1, 2, 3, 4, 5, 6]
});

function main({ millions, buf, type, byteLength }) {
function main({ n, buf, type, byteLength }) {
const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
const buff = new clazz(8);
const fn = `read${type || 'IntBE'}`;

buff.writeDoubleLE(0, 0);
bench.start();
for (var i = 0; i !== millions * 1e6; i++) {
for (var i = 0; i !== n; i++) {
buff[fn](0, byteLength);
}
bench.end(millions);
bench.end(n);
}
9 changes: 5 additions & 4 deletions benchmark/buffers/buffer-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ const types = [
const bench = common.createBenchmark(main, {
buffer: ['fast', 'slow'],
type: types,
millions: [1]
n: [1e6]
});

function main({ millions, buf, type }) {
function main({ n, buf, type }) {
const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
const buff = new clazz(8);
const fn = `read${type || 'UInt8'}`;

buff.writeDoubleLE(0, 0);
bench.start();
for (var i = 0; i !== millions * 1e6; i++) {

for (var i = 0; i !== n; i++) {
buff[fn](0);
}
bench.end(millions);
bench.end(n);
}
28 changes: 14 additions & 14 deletions benchmark/buffers/buffer-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const types = [
const bench = common.createBenchmark(main, {
buffer: ['fast', 'slow'],
type: types,
millions: [1]
n: [1e6]
});

const INT8 = 0x7f;
Expand Down Expand Up @@ -60,42 +60,42 @@ const byteLength = {
writeIntBE: 6
};

function main({ millions, buf, type }) {
function main({ n, buf, type }) {
const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
const buff = new clazz(8);
const fn = `write${type || 'UInt8'}`;

if (!/\d/.test(fn))
benchSpecialInt(buff, fn, millions);
benchSpecialInt(buff, fn, n);
else if (/Int/.test(fn))
benchInt(buff, fn, millions);
benchInt(buff, fn, n);
else
benchFloat(buff, fn, millions);
benchFloat(buff, fn, n);
}

function benchInt(buff, fn, millions) {
function benchInt(buff, fn, n) {
const m = mod[fn];
bench.start();
for (var i = 0; i !== millions * 1e6; i++) {
for (var i = 0; i !== n; i++) {
buff[fn](i & m, 0);
}
bench.end(millions);
bench.end(n);
}

function benchSpecialInt(buff, fn, millions) {
function benchSpecialInt(buff, fn, n) {
const m = mod[fn];
const byte = byteLength[fn];
bench.start();
for (var i = 0; i !== millions * 1e6; i++) {
for (var i = 0; i !== n; i++) {
buff[fn](i & m, 0, byte);
}
bench.end(millions);
bench.end(n);
}

function benchFloat(buff, fn, millions) {
function benchFloat(buff, fn, n) {
bench.start();
for (var i = 0; i !== millions * 1e6; i++) {
for (var i = 0; i !== n; i++) {
buff[fn](i, 0);
}
bench.end(millions);
bench.end(n);
}
13 changes: 6 additions & 7 deletions benchmark/buffers/dataview-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const types = [

const bench = common.createBenchmark(main, {
type: types,
millions: [1]
n: [1e6]
});

const INT8 = 0x7f;
Expand All @@ -39,18 +39,17 @@ const mod = {
setUint32: UINT32
};

function main({ millions, type }) {
function main({ n, type }) {
type = type || 'Uint8';
const len = millions * 1e6;
const ab = new ArrayBuffer(8);
const dv = new DataView(ab, 0, 8);
const le = /LE$/.test(type);
const fn = `set${type.replace(/[LB]E$/, '')}`;

if (/int/i.test(fn))
benchInt(dv, fn, len, le);
benchInt(dv, fn, n, le);
else
benchFloat(dv, fn, len, le);
benchFloat(dv, fn, n, le);
}

function benchInt(dv, fn, len, le) {
Expand All @@ -60,7 +59,7 @@ function benchInt(dv, fn, len, le) {
for (var i = 0; i < len; i++) {
method.call(dv, 0, i % m, le);
}
bench.end(len / 1e6);
bench.end(len);
}

function benchFloat(dv, fn, len, le) {
Expand All @@ -69,5 +68,5 @@ function benchFloat(dv, fn, len, le) {
for (var i = 0; i < len; i++) {
method.call(dv, 0, i * 0.1, le);
}
bench.end(len / 1e6);
bench.end(len);
}
20 changes: 10 additions & 10 deletions benchmark/es/defaultparams-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const assert = require('assert');

const bench = common.createBenchmark(main, {
method: ['withoutdefaults', 'withdefaults'],
millions: [100]
n: [1e8]
});

function oldStyleDefaults(x, y) {
Expand All @@ -20,29 +20,29 @@ function defaultParams(x = 1, y = 2) {
assert.strictEqual(y, 2);
}

function runOldStyleDefaults(millions) {
function runOldStyleDefaults(n) {
bench.start();
for (var i = 0; i < millions * 1e6; i++)
for (var i = 0; i < n; i++)
oldStyleDefaults();
bench.end(millions);
bench.end(n);
}

function runDefaultParams(millions) {
function runDefaultParams(n) {
bench.start();
for (var i = 0; i < millions * 1e6; i++)
for (var i = 0; i < n; i++)
defaultParams();
bench.end(millions);
bench.end(n);
}

function main({ millions, method }) {
function main({ n, method }) {
switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'withoutdefaults':
runOldStyleDefaults(millions);
runOldStyleDefaults(n);
break;
case 'withdefaults':
runDefaultParams(millions);
runDefaultParams(n);
break;
default:
throw new Error(`Unexpected method "${method}"`);
Expand Down
Loading

0 comments on commit b80da63

Please sign in to comment.