Skip to content

Commit ffdc046

Browse 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

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
constcommon=require('../common.js');
3+
constv8=require('v8');
4+
5+
constbench=common.createBenchmark(main,{
6+
size: [16,512,1024,4096,16386],
7+
millions: [1]
8+
});
9+
10+
functionmain(conf){
11+
constiter=(conf.millions>>>0)*1e6;
12+
constsize=(conf.size>>>0);
13+
constb0=newBuffer(size).fill('a');
14+
constb1=newBuffer(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(vari=0;i<iter;i++){
26+
b0.compare(b1);
27+
}
28+
bench.end(iter/1e6);
29+
}

0 commit comments

Comments
 (0)