Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
benchmark: review comments
  • Loading branch information
suryagh committed Jun 11, 2016
commit 100a8be9906558ef921151813199c5cb94bd464d
20 changes: 10 additions & 10 deletions benchmark/misc/util-extend-vs-object-assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@ const util = require('util');
const v8 = require('v8');

const bench = common.createBenchmark(main, {
type: ['util._extend', 'Object.assign',
'util._extend', 'Object.assign'],
type: ['extend', 'assign'],
n: [10e4]
});

function main(params) {
function main(conf) {
let fn;
const n = params.n | 0;
const n = conf.n | 0;
let v8command;

if (params.type == 'util._extend') {
if (conf.type === 'extend') {
fn = util._extend;
v8command = '%OptimizeFunctionOnNextCall(util._extend)';
Copy link
Copy Markdown
Contributor

@mscdex mscdex Jun 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know exactly how %OptimizeFunctionOnNextCall() works/is implemented, but I wonder if util._extend here should instead be fn?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the right way. It will get eval to the correct function reference by v8.


} else if (params.type == 'Object.assign') {
} else if (conf.type === 'assign') {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: https://github.com/nodejs/node/blob/master/benchmark/common.js#L255

the benchmark/common.js now has a method for handling the details of v8 optimization for you. e.g.

function myMethod(a,b) {
  /** ... **/
}
common.v8ForceOptimization(myMethod, 'a', 'b');
myMethod('a', 'b');

fn = Object.assign;
//Object.assign is built-in, cannot be optimized
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space needed after //.

v8command = '';
}

// Force-optimize the method to test so that the benchmark doesn't
// get disrupted by the optimizer kicking in halfway through.
for (let i = 0; i < params.type.length * 10; i += 1)
for (var i = 0; i < conf.type.length * 10; i += 1)
fn({}, process.env);

v8.setFlagsFromString('--allow_natives_syntax');
eval(v8command);

var obj = {};

bench.start();
for (let i = 0; i < n; i += 1)
fn({}, process.env);
for (var j = 0; j < n; j += 1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j++?

Copy link
Copy Markdown
Contributor

@mscdex mscdex Jun 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A ton of benchmarks use += 1 for the main loop already, so I'm not sure it's worth changing as far as consistency goes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var j = n:
while (j--) { ... }

Ok just kidding, it really doesn't matter though :P

fn(obj, process.env);
bench.end(n);
}