2016-02-26 01:26:39 +01:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
|
|
size: [16, 512, 1024, 4096, 16386],
|
2017-01-20 04:26:18 +01:00
|
|
|
args: [1, 2, 3, 4, 5],
|
2018-03-17 16:19:09 +01:00
|
|
|
n: [1e6]
|
2016-02-26 01:26:39 +01:00
|
|
|
});
|
|
|
|
|
2018-03-17 16:19:09 +01:00
|
|
|
function main({ n, size, args }) {
|
2017-01-20 04:26:18 +01:00
|
|
|
const b0 = Buffer.alloc(size, 'a');
|
|
|
|
const b1 = Buffer.alloc(size, 'a');
|
|
|
|
const b0Len = b0.length;
|
|
|
|
const b1Len = b1.length;
|
|
|
|
var i;
|
2016-02-26 01:26:39 +01:00
|
|
|
|
|
|
|
b1[size - 1] = 'b'.charCodeAt(0);
|
|
|
|
|
2017-01-20 04:26:18 +01:00
|
|
|
switch (args) {
|
|
|
|
case 2:
|
|
|
|
b0.compare(b1, 0);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
b0.compare(b1, 0, b1Len);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
b0.compare(b1, 0, b1Len, 0);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
b0.compare(b1, 0, b1Len, 0, b0Len);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
b0.compare(b1);
|
|
|
|
}
|
|
|
|
switch (args) {
|
|
|
|
case 2:
|
|
|
|
b0.compare(b1, 0);
|
|
|
|
bench.start();
|
2018-03-17 16:19:09 +01:00
|
|
|
for (i = 0; i < n; i++) {
|
2017-01-20 04:26:18 +01:00
|
|
|
b0.compare(b1, 0);
|
|
|
|
}
|
2018-03-17 16:19:09 +01:00
|
|
|
bench.end(n);
|
2017-01-20 04:26:18 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
b0.compare(b1, 0, b1Len);
|
|
|
|
bench.start();
|
2018-03-17 16:19:09 +01:00
|
|
|
for (i = 0; i < n; i++) {
|
2017-01-20 04:26:18 +01:00
|
|
|
b0.compare(b1, 0, b1Len);
|
|
|
|
}
|
2018-03-17 16:19:09 +01:00
|
|
|
bench.end(n);
|
2017-01-20 04:26:18 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
b0.compare(b1, 0, b1Len, 0);
|
|
|
|
bench.start();
|
2018-03-17 16:19:09 +01:00
|
|
|
for (i = 0; i < n; i++) {
|
2017-01-20 04:26:18 +01:00
|
|
|
b0.compare(b1, 0, b1Len, 0);
|
|
|
|
}
|
2018-03-17 16:19:09 +01:00
|
|
|
bench.end(n);
|
2017-01-20 04:26:18 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
b0.compare(b1, 0, b1Len, 0, b0Len);
|
|
|
|
bench.start();
|
2018-03-17 16:19:09 +01:00
|
|
|
for (i = 0; i < n; i++) {
|
2017-01-20 04:26:18 +01:00
|
|
|
b0.compare(b1, 0, b1Len, 0, b0Len);
|
|
|
|
}
|
2018-03-17 16:19:09 +01:00
|
|
|
bench.end(n);
|
2017-01-20 04:26:18 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
b0.compare(b1);
|
|
|
|
bench.start();
|
2018-03-17 16:19:09 +01:00
|
|
|
for (i = 0; i < n; i++) {
|
2017-01-20 04:26:18 +01:00
|
|
|
b0.compare(b1);
|
|
|
|
}
|
2018-03-17 16:19:09 +01:00
|
|
|
bench.end(n);
|
2016-02-26 01:26:39 +01:00
|
|
|
}
|
|
|
|
}
|