Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ffdc046

Browse filesBrowse files
committed
benchmark: add benchmark for buf.compare()
There is a benchmark for the class method `Buffer.compare()` but not for the instance method `buf.compare()`. This adds that benchmark. I used this to confirm a performance regression in an implementation I was considering. While the implementation was a bust, it does seem like the benchmark is worthwhile. The benchmark is nearly identical to the existing `Buffer.compare()` benchmark except, of course, that it calls `buf.compare()` instead. PR-URL: #5441 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Evan Lucas <evanlucas@me.com>
1 parent dcfda10 commit ffdc046
Copy full SHA for ffdc046

File tree

Expand file treeCollapse file tree

1 file changed

+29
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-0
lines changed
Open diff view settings
Collapse file
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const v8 = require('v8');
4+
5+
const bench = common.createBenchmark(main, {
6+
size: [16, 512, 1024, 4096, 16386],
7+
millions: [1]
8+
});
9+
10+
function main(conf) {
11+
const iter = (conf.millions >>> 0) * 1e6;
12+
const size = (conf.size >>> 0);
13+
const b0 = new Buffer(size).fill('a');
14+
const b1 = new Buffer(size).fill('a');
15+
16+
b1[size - 1] = 'b'.charCodeAt(0);
17+
18+
// Force optimization before starting the benchmark
19+
b0.compare(b1);
20+
v8.setFlagsFromString('--allow_natives_syntax');
21+
eval('%OptimizeFunctionOnNextCall(b0.compare)');
22+
b0.compare(b1);
23+
24+
bench.start();
25+
for (var i = 0; i < iter; i++) {
26+
b0.compare(b1);
27+
}
28+
bench.end(iter / 1e6);
29+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.