Skip to content
Closed
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
29 changes: 29 additions & 0 deletions benchmark/buffers/buffer-compare-instance-method.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';
const common = require('../common.js');
const v8 = require('v8');

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

function main(conf) {
const iter = (conf.millions >>> 0) * 1e6;
const size = (conf.size >>> 0);
const b0 = new Buffer(size).fill('a');
const b1 = new Buffer(size).fill('a');

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Please insert code to force optimization of b0.compare before starting the benchmark. Take a look at some of the other (e.g. path) benchmarks to see how to do this.

// Force optimization before starting the benchmark
b0.compare(b1);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(b0.compare)');
b0.compare(b1);

bench.start();
for (var i = 0; i < iter; i++) {
b0.compare(b1);
}
bench.end(iter / 1e6);
}