benchmark: changed millions and thousands to n
PR-URL: https://github.com/nodejs/node/pull/18917 Fixes: https://github.com/nodejs/node/issues/18778 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
This commit is contained in:
parent
28e5c462d4
commit
b80da63b99
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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}`;
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ const types = [
|
||||
const bench = common.createBenchmark(main, {
|
||||
buffer: ['fast', 'slow'],
|
||||
type: types,
|
||||
millions: [1]
|
||||
n: [1e6]
|
||||
});
|
||||
|
||||
const INT8 = 0x7f;
|
||||
@ -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);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ const types = [
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
type: types,
|
||||
millions: [1]
|
||||
n: [1e6]
|
||||
});
|
||||
|
||||
const INT8 = 0x7f;
|
||||
@ -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) {
|
||||
@ -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) {
|
||||
@ -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);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ const assert = require('assert');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
method: ['withoutdefaults', 'withdefaults'],
|
||||
millions: [100]
|
||||
n: [1e8]
|
||||
});
|
||||
|
||||
function oldStyleDefaults(x, y) {
|
||||
@ -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}"`);
|
||||
|
@ -5,13 +5,13 @@ const assert = require('assert');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
method: ['swap', 'destructure'],
|
||||
millions: [100]
|
||||
n: [1e8]
|
||||
});
|
||||
|
||||
function runSwapManual(millions) {
|
||||
function runSwapManual(n) {
|
||||
var x, y, r;
|
||||
bench.start();
|
||||
for (var i = 0; i < millions * 1e6; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
x = 1, y = 2;
|
||||
r = x;
|
||||
x = y;
|
||||
@ -19,30 +19,30 @@ function runSwapManual(millions) {
|
||||
assert.strictEqual(x, 2);
|
||||
assert.strictEqual(y, 1);
|
||||
}
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function runSwapDestructured(millions) {
|
||||
function runSwapDestructured(n) {
|
||||
var x, y;
|
||||
bench.start();
|
||||
for (var i = 0; i < millions * 1e6; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
x = 1, y = 2;
|
||||
[x, y] = [y, x];
|
||||
assert.strictEqual(x, 2);
|
||||
assert.strictEqual(y, 1);
|
||||
}
|
||||
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 'swap':
|
||||
runSwapManual(millions);
|
||||
runSwapManual(n);
|
||||
break;
|
||||
case 'destructure':
|
||||
runSwapDestructured(millions);
|
||||
runSwapDestructured(n);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unexpected method "${method}"`);
|
||||
|
@ -4,44 +4,44 @@ const common = require('../common.js');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
method: ['normal', 'destructureObject'],
|
||||
millions: [100]
|
||||
n: [1e8]
|
||||
});
|
||||
|
||||
function runNormal(millions) {
|
||||
function runNormal(n) {
|
||||
var i = 0;
|
||||
const o = { x: 0, y: 1 };
|
||||
bench.start();
|
||||
for (; i < millions * 1e6; i++) {
|
||||
for (; i < n; i++) {
|
||||
/* eslint-disable no-unused-vars */
|
||||
const x = o.x;
|
||||
const y = o.y;
|
||||
const r = o.r || 2;
|
||||
/* eslint-enable no-unused-vars */
|
||||
}
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function runDestructured(millions) {
|
||||
function runDestructured(n) {
|
||||
var i = 0;
|
||||
const o = { x: 0, y: 1 };
|
||||
bench.start();
|
||||
for (; i < millions * 1e6; i++) {
|
||||
for (; i < n; i++) {
|
||||
/* eslint-disable no-unused-vars */
|
||||
const { x, y, r = 2 } = o;
|
||||
/* eslint-enable no-unused-vars */
|
||||
}
|
||||
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 'normal':
|
||||
runNormal(millions);
|
||||
runNormal(n);
|
||||
break;
|
||||
case 'destructureObject':
|
||||
runDestructured(millions);
|
||||
runDestructured(n);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unexpected method "${method}"`);
|
||||
|
@ -5,51 +5,51 @@ const common = require('../common.js');
|
||||
const bench = common.createBenchmark(main, {
|
||||
method: ['for', 'for-of', 'for-in', 'forEach'],
|
||||
count: [5, 10, 20, 100],
|
||||
millions: [5]
|
||||
n: [5e6]
|
||||
});
|
||||
|
||||
function useFor(millions, items, count) {
|
||||
function useFor(n, items, count) {
|
||||
bench.start();
|
||||
for (var i = 0; i < millions * 1e6; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
for (var j = 0; j < count; j++) {
|
||||
/* eslint-disable no-unused-vars */
|
||||
const item = items[j];
|
||||
/* esline-enable no-unused-vars */
|
||||
}
|
||||
}
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function useForOf(millions, items) {
|
||||
function useForOf(n, items) {
|
||||
var item;
|
||||
bench.start();
|
||||
for (var i = 0; i < millions * 1e6; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
for (item of items) {}
|
||||
}
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function useForIn(millions, items) {
|
||||
function useForIn(n, items) {
|
||||
bench.start();
|
||||
for (var i = 0; i < millions * 1e6; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
for (var j in items) {
|
||||
/* eslint-disable no-unused-vars */
|
||||
const item = items[j];
|
||||
/* esline-enable no-unused-vars */
|
||||
}
|
||||
}
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function useForEach(millions, items) {
|
||||
function useForEach(n, items) {
|
||||
bench.start();
|
||||
for (var i = 0; i < millions * 1e6; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
items.forEach((item) => {});
|
||||
}
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function main({ millions, count, method }) {
|
||||
function main({ n, count, method }) {
|
||||
const items = new Array(count);
|
||||
var fn;
|
||||
for (var i = 0; i < count; i++)
|
||||
@ -73,5 +73,5 @@ function main({ millions, count, method }) {
|
||||
default:
|
||||
throw new Error(`Unexpected method "${method}"`);
|
||||
}
|
||||
fn(millions, items, count);
|
||||
fn(n, items, count);
|
||||
}
|
||||
|
@ -8,62 +8,62 @@ const bench = common.createBenchmark(main, {
|
||||
'object', 'nullProtoObject', 'nullProtoLiteralObject', 'storageObject',
|
||||
'fakeMap', 'map'
|
||||
],
|
||||
millions: [1]
|
||||
n: [1e6]
|
||||
});
|
||||
|
||||
function runObject(millions) {
|
||||
function runObject(n) {
|
||||
const m = {};
|
||||
bench.start();
|
||||
for (var i = 0; i < millions * 1e6; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
m[`i${i}`] = i;
|
||||
m[`s${i}`] = String(i);
|
||||
assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]);
|
||||
m[`i${i}`] = undefined;
|
||||
m[`s${i}`] = undefined;
|
||||
}
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function runNullProtoObject(millions) {
|
||||
function runNullProtoObject(n) {
|
||||
const m = Object.create(null);
|
||||
bench.start();
|
||||
for (var i = 0; i < millions * 1e6; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
m[`i${i}`] = i;
|
||||
m[`s${i}`] = String(i);
|
||||
assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]);
|
||||
m[`i${i}`] = undefined;
|
||||
m[`s${i}`] = undefined;
|
||||
}
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function runNullProtoLiteralObject(millions) {
|
||||
function runNullProtoLiteralObject(n) {
|
||||
const m = { __proto__: null };
|
||||
bench.start();
|
||||
for (var i = 0; i < millions * 1e6; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
m[`i${i}`] = i;
|
||||
m[`s${i}`] = String(i);
|
||||
assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]);
|
||||
m[`i${i}`] = undefined;
|
||||
m[`s${i}`] = undefined;
|
||||
}
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function StorageObject() {}
|
||||
StorageObject.prototype = Object.create(null);
|
||||
|
||||
function runStorageObject(millions) {
|
||||
function runStorageObject(n) {
|
||||
const m = new StorageObject();
|
||||
bench.start();
|
||||
for (var i = 0; i < millions * 1e6; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
m[`i${i}`] = i;
|
||||
m[`s${i}`] = String(i);
|
||||
assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]);
|
||||
m[`i${i}`] = undefined;
|
||||
m[`s${i}`] = undefined;
|
||||
}
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function fakeMap() {
|
||||
@ -76,53 +76,53 @@ function fakeMap() {
|
||||
};
|
||||
}
|
||||
|
||||
function runFakeMap(millions) {
|
||||
function runFakeMap(n) {
|
||||
const m = fakeMap();
|
||||
bench.start();
|
||||
for (var i = 0; i < millions * 1e6; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
m.set(`i${i}`, i);
|
||||
m.set(`s${i}`, String(i));
|
||||
assert.strictEqual(String(m.get(`i${i}`)), m.get(`s${i}`));
|
||||
m.set(`i${i}`, undefined);
|
||||
m.set(`s${i}`, undefined);
|
||||
}
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function runMap(millions) {
|
||||
function runMap(n) {
|
||||
const m = new Map();
|
||||
bench.start();
|
||||
for (var i = 0; i < millions * 1e6; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
m.set(`i${i}`, i);
|
||||
m.set(`s${i}`, String(i));
|
||||
assert.strictEqual(String(m.get(`i${i}`)), m.get(`s${i}`));
|
||||
m.set(`i${i}`, undefined);
|
||||
m.set(`s${i}`, undefined);
|
||||
}
|
||||
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 'object':
|
||||
runObject(millions);
|
||||
runObject(n);
|
||||
break;
|
||||
case 'nullProtoObject':
|
||||
runNullProtoObject(millions);
|
||||
runNullProtoObject(n);
|
||||
break;
|
||||
case 'nullProtoLiteralObject':
|
||||
runNullProtoLiteralObject(millions);
|
||||
runNullProtoLiteralObject(n);
|
||||
break;
|
||||
case 'storageObject':
|
||||
runStorageObject(millions);
|
||||
runStorageObject(n);
|
||||
break;
|
||||
case 'fakeMap':
|
||||
runFakeMap(millions);
|
||||
runFakeMap(n);
|
||||
break;
|
||||
case 'map':
|
||||
runMap(millions);
|
||||
runMap(n);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unexpected method "${method}"`);
|
||||
|
@ -5,7 +5,7 @@ const assert = require('assert');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
method: ['copy', 'rest', 'arguments'],
|
||||
millions: [100]
|
||||
n: [1e8]
|
||||
});
|
||||
|
||||
function copyArguments() {
|
||||
@ -33,22 +33,22 @@ function useArguments() {
|
||||
assert.strictEqual(arguments[3], 'b');
|
||||
}
|
||||
|
||||
function runCopyArguments(millions) {
|
||||
for (var i = 0; i < millions * 1e6; i++)
|
||||
function runCopyArguments(n) {
|
||||
for (var i = 0; i < n; i++)
|
||||
copyArguments(1, 2, 'a', 'b');
|
||||
}
|
||||
|
||||
function runRestArguments(millions) {
|
||||
for (var i = 0; i < millions * 1e6; i++)
|
||||
function runRestArguments(n) {
|
||||
for (var i = 0; i < n; i++)
|
||||
restArguments(1, 2, 'a', 'b');
|
||||
}
|
||||
|
||||
function runUseArguments(millions) {
|
||||
for (var i = 0; i < millions * 1e6; i++)
|
||||
function runUseArguments(n) {
|
||||
for (var i = 0; i < n; i++)
|
||||
useArguments(1, 2, 'a', 'b');
|
||||
}
|
||||
|
||||
function main({ millions, method }) {
|
||||
function main({ n, method }) {
|
||||
var fn;
|
||||
switch (method) {
|
||||
case '':
|
||||
@ -66,6 +66,6 @@ function main({ millions, method }) {
|
||||
throw new Error(`Unexpected method "${method}"`);
|
||||
}
|
||||
bench.start();
|
||||
fn(millions);
|
||||
bench.end(millions);
|
||||
fn(n);
|
||||
bench.end(n);
|
||||
}
|
||||
|
@ -6,11 +6,10 @@ const util = require('util');
|
||||
const bench = common.createBenchmark(main, {
|
||||
method: ['spread', 'assign', '_extend'],
|
||||
count: [5, 10, 20],
|
||||
millions: [1]
|
||||
n: [1e6]
|
||||
});
|
||||
|
||||
function main({ millions, context, count, rest, method }) {
|
||||
const n = millions * 1e6;
|
||||
function main({ n, context, count, rest, method }) {
|
||||
|
||||
const src = {};
|
||||
for (let n = 0; n < count; n++)
|
||||
|
@ -8,7 +8,7 @@ const bench = common.createBenchmark(main, {
|
||||
count: [5, 10, 20],
|
||||
context: ['context', 'null'],
|
||||
rest: [0, 1],
|
||||
millions: [5]
|
||||
n: [5e6]
|
||||
});
|
||||
|
||||
function makeTest(count, rest) {
|
||||
@ -23,7 +23,7 @@ function makeTest(count, rest) {
|
||||
}
|
||||
}
|
||||
|
||||
function main({ millions, context, count, rest, method }) {
|
||||
function main({ n, context, count, rest, method }) {
|
||||
const ctx = context === 'context' ? {} : null;
|
||||
var fn = makeTest(count, rest);
|
||||
const args = new Array(count);
|
||||
@ -36,23 +36,23 @@ function main({ millions, context, count, rest, method }) {
|
||||
// Empty string falls through to next line as default, mostly for tests.
|
||||
case 'apply':
|
||||
bench.start();
|
||||
for (i = 0; i < millions * 1e6; i++)
|
||||
for (i = 0; i < n; i++)
|
||||
fn.apply(ctx, args);
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
break;
|
||||
case 'spread':
|
||||
if (ctx !== null)
|
||||
fn = fn.bind(ctx);
|
||||
bench.start();
|
||||
for (i = 0; i < millions * 1e6; i++)
|
||||
for (i = 0; i < n; i++)
|
||||
fn(...args);
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
break;
|
||||
case 'call-spread':
|
||||
bench.start();
|
||||
for (i = 0; i < millions * 1e6; i++)
|
||||
for (i = 0; i < n; i++)
|
||||
fn.call(ctx, ...args);
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unexpected method "${method}"`);
|
||||
|
@ -1,6 +1,6 @@
|
||||
// show the difference between calling a short js function
|
||||
// relative to a comparable C++ function.
|
||||
// Reports millions of calls per second.
|
||||
// Reports n of calls per second.
|
||||
// Note that JS speed goes up, while cxx speed stays about the same.
|
||||
'use strict';
|
||||
|
||||
@ -28,14 +28,14 @@ assert(js() === cxx());
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
type: ['js', 'cxx'],
|
||||
millions: [1, 10, 50]
|
||||
n: [1e6, 1e7, 5e7]
|
||||
});
|
||||
|
||||
function main({ millions, type }) {
|
||||
function main({ n, type }) {
|
||||
const fn = type === 'cxx' ? cxx : js;
|
||||
bench.start();
|
||||
for (var i = 0; i < millions * 1e6; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
fn();
|
||||
}
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ const common = require('../common.js');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
method: ['property', 'string', 'variable', 'symbol'],
|
||||
millions: [1000]
|
||||
n: [1e9]
|
||||
});
|
||||
|
||||
function runProperty(n) {
|
||||
@ -18,7 +18,7 @@ function runProperty(n) {
|
||||
object.p2 = 21;
|
||||
object.p1 += object.p2;
|
||||
}
|
||||
bench.end(n / 1e6);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function runString(n) {
|
||||
@ -30,7 +30,7 @@ function runString(n) {
|
||||
object['p2'] = 21;
|
||||
object['p1'] += object['p2'];
|
||||
}
|
||||
bench.end(n / 1e6);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function runVariable(n) {
|
||||
@ -44,7 +44,7 @@ function runVariable(n) {
|
||||
object[var2] = 21;
|
||||
object[var1] += object[var2];
|
||||
}
|
||||
bench.end(n / 1e6);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function runSymbol(n) {
|
||||
@ -58,11 +58,10 @@ function runSymbol(n) {
|
||||
object[symbol2] = 21;
|
||||
object[symbol1] += object[symbol2];
|
||||
}
|
||||
bench.end(n / 1e6);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function main({ millions, method }) {
|
||||
const n = millions * 1e6;
|
||||
function main({ n, method }) {
|
||||
|
||||
switch (method) {
|
||||
// '' is a default case for tests
|
||||
|
@ -7,16 +7,15 @@ const tmpdir = require('../../test/common/tmpdir');
|
||||
const benchmarkDirectory = path.join(tmpdir.path, 'nodejs-benchmark-module');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
thousands: [50],
|
||||
n: [5e4],
|
||||
fullPath: ['true', 'false'],
|
||||
useCache: ['true', 'false']
|
||||
});
|
||||
|
||||
function main({ thousands, fullPath, useCache }) {
|
||||
function main({ n, fullPath, useCache }) {
|
||||
tmpdir.refresh();
|
||||
try { fs.mkdirSync(benchmarkDirectory); } catch (e) {}
|
||||
|
||||
for (var i = 0; i <= thousands * 1e3; i++) {
|
||||
for (var i = 0; i <= n; i++) {
|
||||
fs.mkdirSync(`${benchmarkDirectory}${i}`);
|
||||
fs.writeFileSync(
|
||||
`${benchmarkDirectory}${i}/package.json`,
|
||||
@ -29,37 +28,37 @@ function main({ thousands, fullPath, useCache }) {
|
||||
}
|
||||
|
||||
if (fullPath === 'true')
|
||||
measureFull(thousands, useCache === 'true');
|
||||
measureFull(n, useCache === 'true');
|
||||
else
|
||||
measureDir(thousands, useCache === 'true');
|
||||
measureDir(n, useCache === 'true');
|
||||
|
||||
tmpdir.refresh();
|
||||
}
|
||||
|
||||
function measureFull(thousands, useCache) {
|
||||
function measureFull(n, useCache) {
|
||||
var i;
|
||||
if (useCache) {
|
||||
for (i = 0; i <= thousands * 1e3; i++) {
|
||||
for (i = 0; i <= n; i++) {
|
||||
require(`${benchmarkDirectory}${i}/index.js`);
|
||||
}
|
||||
}
|
||||
bench.start();
|
||||
for (i = 0; i <= thousands * 1e3; i++) {
|
||||
for (i = 0; i <= n; i++) {
|
||||
require(`${benchmarkDirectory}${i}/index.js`);
|
||||
}
|
||||
bench.end(thousands);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function measureDir(thousands, useCache) {
|
||||
function measureDir(n, useCache) {
|
||||
var i;
|
||||
if (useCache) {
|
||||
for (i = 0; i <= thousands * 1e3; i++) {
|
||||
for (i = 0; i <= n; i++) {
|
||||
require(`${benchmarkDirectory}${i}`);
|
||||
}
|
||||
}
|
||||
bench.start();
|
||||
for (i = 0; i <= thousands * 1e3; i++) {
|
||||
for (i = 0; i <= n; i++) {
|
||||
require(`${benchmarkDirectory}${i}`);
|
||||
}
|
||||
bench.end(thousands);
|
||||
bench.end(n);
|
||||
}
|
||||
|
@ -2,36 +2,35 @@
|
||||
|
||||
const common = require('../common.js');
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [4]
|
||||
n: [4e6]
|
||||
});
|
||||
|
||||
function main({ millions }) {
|
||||
const N = millions * 1e6;
|
||||
var n = 0;
|
||||
function main({ n }) {
|
||||
var j = 0;
|
||||
|
||||
function cb1(arg1) {
|
||||
n++;
|
||||
if (n === N)
|
||||
bench.end(n / 1e6);
|
||||
j++;
|
||||
if (j === n)
|
||||
bench.end(n);
|
||||
}
|
||||
function cb2(arg1, arg2) {
|
||||
n++;
|
||||
if (n === N)
|
||||
bench.end(n / 1e6);
|
||||
j++;
|
||||
if (j === n)
|
||||
bench.end(n);
|
||||
}
|
||||
function cb3(arg1, arg2, arg3) {
|
||||
n++;
|
||||
if (n === N)
|
||||
bench.end(n / 1e6);
|
||||
j++;
|
||||
if (j === n)
|
||||
bench.end(n);
|
||||
}
|
||||
function cb4(arg1, arg2, arg3, arg4) {
|
||||
n++;
|
||||
if (n === N)
|
||||
bench.end(n / 1e6);
|
||||
j++;
|
||||
if (j === n)
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < N; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
if (i % 4 === 0)
|
||||
process.nextTick(cb4, 3.14, 1024, true, false);
|
||||
else if (i % 3 === 0)
|
||||
|
@ -2,21 +2,20 @@
|
||||
|
||||
const common = require('../common.js');
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [4]
|
||||
n: [4e6]
|
||||
});
|
||||
|
||||
function main({ millions }) {
|
||||
const N = millions * 1e6;
|
||||
var n = 0;
|
||||
function main({ n }) {
|
||||
var j = 0;
|
||||
|
||||
function cb() {
|
||||
n++;
|
||||
if (n === N)
|
||||
bench.end(n / 1e6);
|
||||
j++;
|
||||
if (j === n)
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < N; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
process.nextTick(cb);
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,12 @@
|
||||
|
||||
const common = require('../common.js');
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [12]
|
||||
n: [12e6]
|
||||
});
|
||||
|
||||
process.maxTickDepth = Infinity;
|
||||
|
||||
function main({ millions }) {
|
||||
var n = millions * 1e6;
|
||||
|
||||
function main({ n }) {
|
||||
function cb4(arg1, arg2, arg3, arg4) {
|
||||
if (--n) {
|
||||
if (n % 4 === 0)
|
||||
@ -21,7 +19,7 @@ function main({ millions }) {
|
||||
else
|
||||
process.nextTick(cb1, 0);
|
||||
} else
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
function cb3(arg1, arg2, arg3) {
|
||||
if (--n) {
|
||||
@ -34,7 +32,7 @@ function main({ millions }) {
|
||||
else
|
||||
process.nextTick(cb1, 0);
|
||||
} else
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
function cb2(arg1, arg2) {
|
||||
if (--n) {
|
||||
@ -47,7 +45,7 @@ function main({ millions }) {
|
||||
else
|
||||
process.nextTick(cb1, 0);
|
||||
} else
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
function cb1(arg1) {
|
||||
if (--n) {
|
||||
@ -60,7 +58,7 @@ function main({ millions }) {
|
||||
else
|
||||
process.nextTick(cb1, 0);
|
||||
} else
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
bench.start();
|
||||
process.nextTick(cb1, true);
|
||||
|
@ -1,13 +1,12 @@
|
||||
'use strict';
|
||||
const common = require('../common.js');
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [12]
|
||||
n: [12e6]
|
||||
});
|
||||
|
||||
process.maxTickDepth = Infinity;
|
||||
|
||||
function main({ millions }) {
|
||||
var n = millions * 1e6;
|
||||
function main({ n }) {
|
||||
|
||||
bench.start();
|
||||
process.nextTick(onNextTick);
|
||||
@ -15,6 +14,6 @@ function main({ millions }) {
|
||||
if (--n)
|
||||
process.nextTick(onNextTick);
|
||||
else
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
'use strict';
|
||||
const common = require('../common.js');
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [5]
|
||||
n: [5e6]
|
||||
});
|
||||
|
||||
function main({ millions }) {
|
||||
var n = millions * 1e6;
|
||||
function main({ n }) {
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
@ -20,6 +19,6 @@ function main({ millions }) {
|
||||
}
|
||||
function onNextTick(i) {
|
||||
if (i + 1 === n)
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
'use strict';
|
||||
const common = require('../common.js');
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [5]
|
||||
n: [5e6]
|
||||
});
|
||||
|
||||
function main({ millions }) {
|
||||
var n = millions * 1e6;
|
||||
function main({ n }) {
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
@ -13,6 +12,6 @@ function main({ millions }) {
|
||||
}
|
||||
function onNextTick(i) {
|
||||
if (i + 1 === n)
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ const common = require('../common');
|
||||
const Readable = require('stream').Readable;
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
n: [100e1]
|
||||
n: [1e3]
|
||||
});
|
||||
|
||||
function main({ n }) {
|
||||
|
@ -4,7 +4,7 @@ const common = require('../common');
|
||||
const Readable = require('stream').Readable;
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
n: [100e1]
|
||||
n: [1e3]
|
||||
});
|
||||
|
||||
function main({ n }) {
|
||||
|
@ -4,7 +4,7 @@ const common = require('../common');
|
||||
const Readable = require('stream').Readable;
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
n: [100e1]
|
||||
n: [1e3]
|
||||
});
|
||||
|
||||
function main({ n }) {
|
||||
|
@ -2,30 +2,29 @@
|
||||
const common = require('../common.js');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
thousands: [5000],
|
||||
n: [5e6],
|
||||
type: ['depth', 'depth1', 'breadth', 'breadth1', 'breadth4', 'clear']
|
||||
});
|
||||
|
||||
function main({ thousands, type }) {
|
||||
const N = thousands * 1e3;
|
||||
function main({ n, type }) {
|
||||
switch (type) {
|
||||
case 'depth':
|
||||
depth(N);
|
||||
depth(n);
|
||||
break;
|
||||
case 'depth1':
|
||||
depth1(N);
|
||||
depth1(n);
|
||||
break;
|
||||
case 'breadth':
|
||||
breadth(N);
|
||||
breadth(n);
|
||||
break;
|
||||
case 'breadth1':
|
||||
breadth1(N);
|
||||
breadth1(n);
|
||||
break;
|
||||
case 'breadth4':
|
||||
breadth4(N);
|
||||
breadth4(n);
|
||||
break;
|
||||
case 'clear':
|
||||
clear(N);
|
||||
clear(n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -38,7 +37,7 @@ function depth(N) {
|
||||
function cb() {
|
||||
n++;
|
||||
if (n === N)
|
||||
bench.end(N / 1e3);
|
||||
bench.end(n);
|
||||
else
|
||||
setImmediate(cb);
|
||||
}
|
||||
@ -52,7 +51,7 @@ function depth1(N) {
|
||||
function cb(a1) {
|
||||
n++;
|
||||
if (n === N)
|
||||
bench.end(N / 1e3);
|
||||
bench.end(N);
|
||||
else
|
||||
setImmediate(cb, 1);
|
||||
}
|
||||
@ -65,7 +64,7 @@ function breadth(N) {
|
||||
function cb() {
|
||||
n++;
|
||||
if (n === N)
|
||||
bench.end(N / 1e3);
|
||||
bench.end(N);
|
||||
}
|
||||
for (var i = 0; i < N; i++) {
|
||||
setImmediate(cb);
|
||||
@ -79,7 +78,7 @@ function breadth1(N) {
|
||||
function cb(a1) {
|
||||
n++;
|
||||
if (n === N)
|
||||
bench.end(N / 1e3);
|
||||
bench.end(n);
|
||||
}
|
||||
for (var i = 0; i < N; i++) {
|
||||
setImmediate(cb, 1);
|
||||
@ -94,7 +93,7 @@ function breadth4(N) {
|
||||
function cb(a1, a2, a3, a4) {
|
||||
n++;
|
||||
if (n === N)
|
||||
bench.end(N / 1e3);
|
||||
bench.end(n);
|
||||
}
|
||||
for (var i = 0; i < N; i++) {
|
||||
setImmediate(cb, 1, 2, 3, 4);
|
||||
@ -106,7 +105,7 @@ function clear(N) {
|
||||
bench.start();
|
||||
function cb(a1) {
|
||||
if (a1 === 2)
|
||||
bench.end(N / 1e3);
|
||||
bench.end(N);
|
||||
}
|
||||
for (var i = 0; i < N; i++) {
|
||||
clearImmediate(setImmediate(cb, 1));
|
||||
|
@ -2,14 +2,13 @@
|
||||
|
||||
const common = require('../common.js');
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [5]
|
||||
n: [5e6]
|
||||
});
|
||||
|
||||
function main({ millions }) {
|
||||
const N = millions * 1e6;
|
||||
function main({ n }) {
|
||||
|
||||
process.on('exit', function() {
|
||||
bench.end(N / 1e6);
|
||||
bench.end(n);
|
||||
});
|
||||
|
||||
function cb1(arg1) {}
|
||||
@ -17,7 +16,7 @@ function main({ millions }) {
|
||||
function cb3(arg1, arg2, arg3) {}
|
||||
|
||||
bench.start();
|
||||
for (let i = 0; i < N; i++) {
|
||||
for (let i = 0; i < n; i++) {
|
||||
if (i % 3 === 0)
|
||||
setImmediate(cb3, 512, true, null, 512, true, null);
|
||||
else if (i % 2 === 0)
|
||||
|
@ -2,20 +2,19 @@
|
||||
|
||||
const common = require('../common.js');
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [10]
|
||||
n: [1e7]
|
||||
});
|
||||
|
||||
function main({ millions }) {
|
||||
const N = millions * 1e6;
|
||||
function main({ n }) {
|
||||
|
||||
process.on('exit', function() {
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
});
|
||||
|
||||
function cb() {}
|
||||
|
||||
bench.start();
|
||||
for (let i = 0; i < N; i++) {
|
||||
for (let i = 0; i < n; i++) {
|
||||
setImmediate(cb);
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,13 @@
|
||||
|
||||
const common = require('../common.js');
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [5]
|
||||
n: [5e6]
|
||||
});
|
||||
|
||||
function main({ millions }) {
|
||||
const N = millions * 1e6;
|
||||
function main({ n }) {
|
||||
|
||||
process.on('exit', function() {
|
||||
bench.end(millions);
|
||||
bench.end(n);
|
||||
});
|
||||
|
||||
function cb3(n, arg2, arg3) {
|
||||
@ -43,5 +42,5 @@ function main({ millions }) {
|
||||
}
|
||||
}
|
||||
bench.start();
|
||||
setImmediate(cb1, N);
|
||||
setImmediate(cb1, n);
|
||||
}
|
||||
|
@ -2,19 +2,18 @@
|
||||
const common = require('../common.js');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
thousands: [5000],
|
||||
n: [5e6],
|
||||
});
|
||||
|
||||
function main({ thousands }) {
|
||||
const N = thousands * 1e3;
|
||||
var n = 0;
|
||||
function main({ n }) {
|
||||
var j = 0;
|
||||
bench.start();
|
||||
function cb() {
|
||||
n++;
|
||||
if (n === N)
|
||||
bench.end(N / 1e3);
|
||||
j++;
|
||||
if (j === n)
|
||||
bench.end(n);
|
||||
}
|
||||
for (var i = 0; i < N; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
setTimeout(cb, 1);
|
||||
}
|
||||
}
|
||||
|
@ -3,14 +3,13 @@ const common = require('../common.js');
|
||||
const assert = require('assert');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [5],
|
||||
n: [5e6],
|
||||
});
|
||||
|
||||
function main({ millions }) {
|
||||
const iterations = millions * 1e6;
|
||||
function main({ n }) {
|
||||
|
||||
var timer = setTimeout(() => {}, 1);
|
||||
for (var i = 0; i < iterations; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
setTimeout(cb, 1);
|
||||
}
|
||||
var next = timer._idlePrev;
|
||||
@ -18,13 +17,13 @@ function main({ millions }) {
|
||||
|
||||
bench.start();
|
||||
|
||||
for (var j = 0; j < iterations; j++) {
|
||||
for (var j = 0; j < n; j++) {
|
||||
timer = next;
|
||||
next = timer._idlePrev;
|
||||
clearTimeout(timer);
|
||||
}
|
||||
|
||||
bench.end(iterations / 1e6);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function cb() {
|
||||
|
@ -3,22 +3,21 @@ const common = require('../common.js');
|
||||
const assert = require('assert');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [1],
|
||||
n: [1e6],
|
||||
});
|
||||
|
||||
function main({ millions }) {
|
||||
const iterations = millions * 1e6;
|
||||
function main({ n }) {
|
||||
|
||||
const timersList = [];
|
||||
for (var i = 0; i < iterations; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
timersList.push(setTimeout(cb, i + 1));
|
||||
}
|
||||
|
||||
bench.start();
|
||||
for (var j = 0; j < iterations + 1; j++) {
|
||||
for (var j = 0; j < n + 1; j++) {
|
||||
clearTimeout(timersList[j]);
|
||||
}
|
||||
bench.end(iterations / 1e6);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function cb() {
|
||||
|
@ -2,18 +2,17 @@
|
||||
const common = require('../common.js');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
thousands: [1],
|
||||
n: [1e3],
|
||||
});
|
||||
|
||||
function main({ thousands }) {
|
||||
const N = thousands * 1e3;
|
||||
var n = 0;
|
||||
function main({ n }) {
|
||||
var i = 0;
|
||||
bench.start();
|
||||
setTimeout(cb, 1);
|
||||
function cb() {
|
||||
n++;
|
||||
if (n === N)
|
||||
bench.end(N / 1e3);
|
||||
i++;
|
||||
if (i === n)
|
||||
bench.end(n);
|
||||
else
|
||||
setTimeout(cb, 1);
|
||||
}
|
||||
|
@ -2,17 +2,16 @@
|
||||
const common = require('../common.js');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [5],
|
||||
n: [5e6],
|
||||
});
|
||||
|
||||
function main({ millions }) {
|
||||
const iterations = millions * 1e6;
|
||||
function main({ n }) {
|
||||
|
||||
bench.start();
|
||||
|
||||
for (var i = 0; i < iterations; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
setTimeout(() => {}, 1);
|
||||
}
|
||||
|
||||
bench.end(iterations / 1e6);
|
||||
bench.end(n);
|
||||
}
|
||||
|
@ -3,21 +3,19 @@ const common = require('../common.js');
|
||||
const assert = require('assert');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [1],
|
||||
n: [1e6],
|
||||
});
|
||||
|
||||
function main({ millions }) {
|
||||
const iterations = millions * 1e6;
|
||||
|
||||
function main({ n }) {
|
||||
const timersList = [];
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < iterations; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
timersList.push(setTimeout(cb, i + 1));
|
||||
}
|
||||
bench.end(iterations / 1e6);
|
||||
bench.end(n);
|
||||
|
||||
for (var j = 0; j < iterations + 1; j++) {
|
||||
for (var j = 0; j < n + 1; j++) {
|
||||
clearTimeout(timersList[j]);
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,10 @@ const common = require('../common.js');
|
||||
// which then get executed on the next uv tick
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
millions: [10],
|
||||
n: [1e7],
|
||||
});
|
||||
|
||||
function main({ millions }) {
|
||||
const iterations = millions * 1e6;
|
||||
function main({ n }) {
|
||||
let count = 0;
|
||||
|
||||
// Function tracking on the hidden class in V8 can cause misleading
|
||||
@ -18,16 +17,16 @@ function main({ millions }) {
|
||||
|
||||
function cb() {
|
||||
count++;
|
||||
if (count === iterations)
|
||||
bench.end(iterations / 1e6);
|
||||
if (count === n)
|
||||
bench.end(n);
|
||||
}
|
||||
function cb2() {
|
||||
count++;
|
||||
if (count === iterations)
|
||||
bench.end(iterations / 1e6);
|
||||
if (count === n)
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
for (var i = 0; i < iterations; i++) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
setTimeout(i % 2 ? cb : cb2, 1);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ const runBenchmark = require('../common/benchmark');
|
||||
runBenchmark('es',
|
||||
[
|
||||
'method=',
|
||||
'millions=0.000001',
|
||||
'count=1',
|
||||
'context=null',
|
||||
'rest=0',
|
||||
|
@ -7,7 +7,6 @@ const runBenchmark = require('../common/benchmark');
|
||||
runBenchmark('misc', [
|
||||
'concat=0',
|
||||
'method=',
|
||||
'millions=.000001',
|
||||
'n=1',
|
||||
'type=extend',
|
||||
'val=magyarország.icom.museum'
|
||||
|
@ -5,7 +5,7 @@ require('../common');
|
||||
const runBenchmark = require('../common/benchmark');
|
||||
|
||||
runBenchmark('module', [
|
||||
'thousands=.001',
|
||||
'n=1',
|
||||
'useCache=true',
|
||||
'fullPath=true'
|
||||
]);
|
||||
|
@ -6,7 +6,6 @@ const runBenchmark = require('../common/benchmark');
|
||||
|
||||
runBenchmark('process',
|
||||
[
|
||||
'millions=0.000001',
|
||||
'n=1',
|
||||
'type=raw'
|
||||
], { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
|
||||
|
@ -7,8 +7,6 @@ const runBenchmark = require('../common/benchmark');
|
||||
runBenchmark('timers',
|
||||
[
|
||||
'type=depth',
|
||||
'n=1',
|
||||
'millions=0.000001',
|
||||
'thousands=0.001'
|
||||
'n=1'
|
||||
],
|
||||
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
|
||||
|
@ -1,12 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
const http2 = require('http2');
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
|
||||
const http2 = require('http2');
|
||||
|
||||
for (const chunkSequence of [
|
||||
[ '' ],
|
||||
|
@ -13,7 +13,6 @@ runBenchmark('buffers',
|
||||
'encoding=utf8',
|
||||
'endian=BE',
|
||||
'len=2',
|
||||
'millions=0.000001',
|
||||
'method=',
|
||||
'n=1',
|
||||
'pieces=1',
|
||||
|
Loading…
x
Reference in New Issue
Block a user