Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: var to const #13757

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benchmark/_benchmark_progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const readline = require('readline');

function pad(input, minLength, fill) {
var result = String(input);
var padding = fill.repeat(Math.max(0, minLength - result.length));
const result = String(input);
const padding = fill.repeat(Math.max(0, minLength - result.length));
return `${padding}${result}`;
}

Expand Down
2 changes: 1 addition & 1 deletion benchmark/arrays/var-int.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function main(conf) {
const n = +conf.n;

bench.start();
var arr = new clazz(n * 1e6);
const arr = new clazz(n * 1e6);
for (var i = 0; i < 10; ++i) {
run();
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/arrays/zero-float.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function main(conf) {
const n = +conf.n;

bench.start();
var arr = new clazz(n * 1e6);
const arr = new clazz(n * 1e6);
for (var i = 0; i < 10; ++i) {
run();
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/arrays/zero-int.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function main(conf) {
const n = +conf.n;

bench.start();
var arr = new clazz(n * 1e6);
const arr = new clazz(n * 1e6);
for (var i = 0; i < 10; ++i) {
run();
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-base64-encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
var common = require('../common.js');
const common = require('../common.js');

const bench = common.createBenchmark(main, {
len: [64 * 1024 * 1024],
Expand Down
20 changes: 10 additions & 10 deletions benchmark/buffers/buffer-bytelength.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
'use strict';
var common = require('../common');
const common = require('../common');

var bench = common.createBenchmark(main, {
const bench = common.createBenchmark(main, {
encoding: ['utf8', 'base64', 'buffer'],
len: [1, 2, 4, 16, 64, 256], // x16
n: [5e6]
});

// 16 chars each
var chars = [
const chars = [
'hello brendan!!!', // 1 byte
'ΰαβγδεζηθικλμνξο', // 2 bytes
'挰挱挲挳挴挵挶挷挸挹挺挻挼挽挾挿', // 3 bytes
'𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢' // 4 bytes
];

function main(conf) {
var n = conf.n | 0;
var len = conf.len | 0;
var encoding = conf.encoding;
const n = conf.n | 0;
const len = conf.len | 0;
const encoding = conf.encoding;

var strings = [];
var results;
if (encoding === 'buffer') {
strings = [ Buffer.alloc(len * 16, 'a') ];
results = [ len * 16 ];
} else {
for (var string of chars) {
for (const string of chars) {
// Strings must be built differently, depending on encoding
var data = string.repeat(len);
const data = string.repeat(len);
if (encoding === 'utf8') {
strings.push(data);
} else if (encoding === 'base64') {
Expand All @@ -45,9 +45,9 @@ function main(conf) {

bench.start();
for (var i = 0; i < n; i++) {
var index = n % strings.length;
const index = n % strings.length;
// Go!
var r = Buffer.byteLength(strings[index], encoding);
const r = Buffer.byteLength(strings[index], encoding);

if (r !== results[index])
throw new Error('incorrect return value');
Expand Down
4 changes: 2 additions & 2 deletions benchmark/buffers/buffer-compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
var common = require('../common.js');
const common = require('../common.js');

var bench = common.createBenchmark(main, {
const bench = common.createBenchmark(main, {
size: [16, 512, 1024, 4096, 16386],
millions: [1]
});
Expand Down
8 changes: 4 additions & 4 deletions benchmark/buffers/buffer-indexof.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var common = require('../common.js');
var fs = require('fs');
const common = require('../common.js');
const fs = require('fs');
const path = require('path');

const searchStrings = [
Expand All @@ -21,15 +21,15 @@ const searchStrings = [
'</i> to the Caterpillar'
];

var bench = common.createBenchmark(main, {
const bench = common.createBenchmark(main, {
search: searchStrings,
encoding: ['undefined', 'utf8', 'ucs2', 'binary'],
type: ['buffer', 'string'],
iter: [1]
});

function main(conf) {
var iter = (conf.iter) * 100000;
const iter = (conf.iter) * 100000;
var aliceBuffer = fs.readFileSync(
path.resolve(__dirname, '../fixtures/alice.html')
);
Expand Down
14 changes: 7 additions & 7 deletions benchmark/buffers/buffer-iterate.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict';
var SlowBuffer = require('buffer').SlowBuffer;
var common = require('../common.js');
var assert = require('assert');
const SlowBuffer = require('buffer').SlowBuffer;
const common = require('../common.js');
const assert = require('assert');

var bench = common.createBenchmark(main, {
const bench = common.createBenchmark(main, {
size: [16, 512, 1024, 4096, 16386],
type: ['fast', 'slow'],
method: ['for', 'forOf', 'iterator'],
n: [1e3]
});

var methods = {
const methods = {
'for': benchFor,
'forOf': benchForOf,
'iterator': benchIterator
Expand Down Expand Up @@ -43,7 +43,7 @@ function benchForOf(buffer, n) {
bench.start();

for (var k = 0; k < n; k++) {
for (var b of buffer) {
for (const b of buffer) {
assert(b === 0);
}
}
Expand All @@ -54,7 +54,7 @@ function benchIterator(buffer, n) {
bench.start();

for (var k = 0; k < n; k++) {
var iter = buffer[Symbol.iterator]();
const iter = buffer[Symbol.iterator]();
var cur = iter.next();

while (!cur.done) {
Expand Down
6 changes: 3 additions & 3 deletions benchmark/buffers/buffer-read.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
var common = require('../common.js');
const common = require('../common.js');

var types = [
const types = [
'UInt8',
'UInt16LE',
'UInt16BE',
Expand All @@ -18,7 +18,7 @@ var types = [
'DoubleBE'
];

var bench = common.createBenchmark(main, {
const bench = common.createBenchmark(main, {
noAssert: ['false', 'true'],
buffer: ['fast', 'slow'],
type: types,
Expand Down
14 changes: 7 additions & 7 deletions benchmark/buffers/buffer-slice.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict';
var common = require('../common.js');
var SlowBuffer = require('buffer').SlowBuffer;
const common = require('../common.js');
const SlowBuffer = require('buffer').SlowBuffer;

var bench = common.createBenchmark(main, {
const bench = common.createBenchmark(main, {
type: ['fast', 'slow'],
n: [1024]
});

var buf = Buffer.allocUnsafe(1024);
var slowBuf = new SlowBuffer(1024);
const buf = Buffer.allocUnsafe(1024);
const slowBuf = new SlowBuffer(1024);

function main(conf) {
var n = +conf.n;
var b = conf.type === 'fast' ? buf : slowBuf;
const n = +conf.n;
const b = conf.type === 'fast' ? buf : slowBuf;
bench.start();
for (var i = 0; i < n * 1024; i++) {
b.slice(10, 256);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/buffers/buffer-tojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const bench = common.createBenchmark(main, {
});

function main(conf) {
var n = +conf.n;
var buf = Buffer.allocUnsafe(+conf.len);
const n = +conf.n;
const buf = Buffer.allocUnsafe(+conf.len);

bench.start();
for (var i = 0; i < n; ++i)
Expand Down
14 changes: 7 additions & 7 deletions benchmark/buffers/buffer-write.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
var common = require('../common.js');
const common = require('../common.js');

var types = [
const types = [
'UInt8',
'UInt16LE',
'UInt16BE',
Expand All @@ -18,7 +18,7 @@ var types = [
'DoubleBE'
];

var bench = common.createBenchmark(main, {
const bench = common.createBenchmark(main, {
noAssert: ['false', 'true'],
buffer: ['fast', 'slow'],
type: types,
Expand All @@ -32,7 +32,7 @@ const UINT8 = (INT8 * 2) + 1;
const UINT16 = (INT16 * 2) + 1;
const UINT32 = INT32;

var mod = {
const mod = {
writeInt8: INT8,
writeInt16BE: INT16,
writeInt16LE: INT16,
Expand Down Expand Up @@ -60,8 +60,8 @@ function main(conf) {
}

function benchInt(buff, fn, len, noAssert) {
var m = mod[fn];
var testFunction = new Function('buff', `
const m = mod[fn];
const testFunction = new Function('buff', `
for (var i = 0; i !== ${len}; i++) {
buff.${fn}(i & ${m}, 0, ${JSON.stringify(noAssert)});
}
Expand All @@ -72,7 +72,7 @@ function benchInt(buff, fn, len, noAssert) {
}

function benchFloat(buff, fn, len, noAssert) {
var testFunction = new Function('buff', `
const testFunction = new Function('buff', `
for (var i = 0; i !== ${len}; i++) {
buff.${fn}(i, 0, ${JSON.stringify(noAssert)});
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer_zero.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const zeroBuffer = Buffer.alloc(0);
const zeroString = '';

function main(conf) {
var n = +conf.n;
const n = +conf.n;
bench.start();

if (conf.type === 'buffer')
Expand Down
8 changes: 4 additions & 4 deletions benchmark/buffers/dataview-set.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
var common = require('../common.js');
const common = require('../common.js');

var types = [
const types = [
'Uint8',
'Uint16LE',
'Uint16BE',
Expand All @@ -18,7 +18,7 @@ var types = [
'Float64BE'
];

var bench = common.createBenchmark(main, {
const bench = common.createBenchmark(main, {
type: types,
millions: [1]
});
Expand All @@ -30,7 +30,7 @@ const UINT8 = INT8 * 2;
const UINT16 = INT16 * 2;
const UINT32 = INT32 * 2;

var mod = {
const mod = {
setInt8: INT8,
setInt16: INT16,
setInt32: INT32,
Expand Down
2 changes: 1 addition & 1 deletion benchmark/child_process/child-process-exec-stdout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const common = require('../common.js');
const { exec, execSync } = require('child_process');
const isWindows = process.platform === 'win32';

var messagesLength = [64, 256, 1024, 4096];
const messagesLength = [64, 256, 1024, 4096];
// Windows does not support command lines longer than 8191 characters
if (!isWindows) messagesLength.push(32768);

Expand Down
2 changes: 1 addition & 1 deletion benchmark/child_process/child-process-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const common = require('../common.js');
const os = require('os');
const child_process = require('child_process');

var messagesLength = [64, 256, 1024, 4096];
const messagesLength = [64, 256, 1024, 4096];
// Windows does not support that long arguments
if (os.platform() !== 'win32')
messagesLength.push(32768);
Expand Down
10 changes: 5 additions & 5 deletions benchmark/child_process/spawn-echo.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
var common = require('../common.js');
var bench = common.createBenchmark(main, {
const common = require('../common.js');
const bench = common.createBenchmark(main, {
n: [1000]
});

var spawn = require('child_process').spawn;
const spawn = require('child_process').spawn;
function main(conf) {
var n = +conf.n;
const n = +conf.n;

bench.start();
go(n, n);
Expand All @@ -16,7 +16,7 @@ function go(n, left) {
if (--left === 0)
return bench.end(n);

var child = spawn('echo', ['hello']);
const child = spawn('echo', ['hello']);
child.on('exit', function(code) {
if (code)
process.exit(code);
Expand Down
8 changes: 4 additions & 4 deletions benchmark/cluster/echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ if (cluster.isMaster) {
});

function main(conf) {
var n = +conf.n;
var workers = +conf.workers;
var sends = +conf.sendsPerBroadcast;
var expectedPerBroadcast = sends * workers;
const n = +conf.n;
const workers = +conf.workers;
const sends = +conf.sendsPerBroadcast;
const expectedPerBroadcast = sends * workers;
var payload;
var readies = 0;
var broadcasts = 0;
Expand Down
Loading