2016-02-20 02:03:16 +01:00
|
|
|
'use strict';
|
2017-09-14 03:48:53 +02:00
|
|
|
const common = require('../common.js');
|
|
|
|
const fs = require('fs');
|
2016-03-02 22:38:23 +01:00
|
|
|
const path = require('path');
|
2015-09-03 10:10:30 +02:00
|
|
|
|
2016-11-24 20:43:35 +01:00
|
|
|
const searchStrings = [
|
|
|
|
'@',
|
|
|
|
'SQ',
|
|
|
|
'10x',
|
|
|
|
'--l',
|
|
|
|
'Alice',
|
|
|
|
'Gryphon',
|
|
|
|
'Panther',
|
|
|
|
'Ou est ma chatte?',
|
|
|
|
'found it very',
|
|
|
|
'among mad people',
|
|
|
|
'neighbouring pool',
|
|
|
|
'Soo--oop',
|
|
|
|
'aaaaaaaaaaaaaaaaa',
|
|
|
|
'venture to go near the house till she had brought herself down to',
|
|
|
|
'</i> to the Caterpillar'
|
|
|
|
];
|
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const bench = common.createBenchmark(main, {
|
2016-11-24 20:43:35 +01:00
|
|
|
search: searchStrings,
|
2015-09-03 10:10:30 +02:00
|
|
|
encoding: ['undefined', 'utf8', 'ucs2', 'binary'],
|
|
|
|
type: ['buffer', 'string'],
|
2018-04-18 12:15:00 +02:00
|
|
|
n: [100000]
|
2015-09-03 10:10:30 +02:00
|
|
|
});
|
|
|
|
|
2018-04-18 12:15:00 +02:00
|
|
|
function main({ n, search, encoding, type }) {
|
2016-03-02 22:38:23 +01:00
|
|
|
var aliceBuffer = fs.readFileSync(
|
|
|
|
path.resolve(__dirname, '../fixtures/alice.html')
|
|
|
|
);
|
2015-09-03 10:10:30 +02:00
|
|
|
|
|
|
|
if (encoding === 'undefined') {
|
|
|
|
encoding = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (encoding === 'ucs2') {
|
2016-01-26 00:00:06 +01:00
|
|
|
aliceBuffer = Buffer.from(aliceBuffer.toString(), encoding);
|
2015-09-03 10:10:30 +02:00
|
|
|
}
|
|
|
|
|
2017-12-30 03:59:57 +01:00
|
|
|
if (type === 'buffer') {
|
2016-01-26 00:00:06 +01:00
|
|
|
search = Buffer.from(Buffer.from(search).toString(), encoding);
|
2015-09-03 10:10:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bench.start();
|
2018-04-18 12:15:00 +02:00
|
|
|
for (var i = 0; i < n; i++) {
|
2015-09-03 10:10:30 +02:00
|
|
|
aliceBuffer.indexOf(search, 0, encoding);
|
|
|
|
}
|
2018-04-18 12:15:00 +02:00
|
|
|
bench.end(n);
|
2015-09-03 10:10:30 +02:00
|
|
|
}
|