2016-02-19 17:03:16 -08:00
|
|
|
'use strict';
|
2017-09-13 22:48:53 -03:00
|
|
|
const common = require('../common.js');
|
|
|
|
const fs = require('fs');
|
2016-03-02 13:38:23 -08:00
|
|
|
const path = require('path');
|
2015-09-03 10:10:30 +02:00
|
|
|
|
2016-11-24 11:43:35 -08:00
|
|
|
const searchStrings = [
|
|
|
|
'@',
|
|
|
|
'SQ',
|
|
|
|
'--l',
|
|
|
|
'Alice',
|
|
|
|
'Gryphon',
|
|
|
|
'Ou est ma chatte?',
|
|
|
|
'found it very',
|
|
|
|
'neighbouring pool',
|
|
|
|
'aaaaaaaaaaaaaaaaa',
|
|
|
|
'venture to go near the house till she had brought herself down to',
|
2019-02-04 22:06:08 -08:00
|
|
|
'</i> to the Caterpillar',
|
2016-11-24 11:43:35 -08:00
|
|
|
];
|
|
|
|
|
2017-09-13 22:48:53 -03:00
|
|
|
const bench = common.createBenchmark(main, {
|
2016-11-24 11:43:35 -08:00
|
|
|
search: searchStrings,
|
2022-12-04 14:12:38 -05:00
|
|
|
encoding: ['undefined', 'utf8', 'ucs2'],
|
2015-09-03 10:10:30 +02:00
|
|
|
type: ['buffer', 'string'],
|
2023-02-04 19:19:25 +01:00
|
|
|
n: [5e4],
|
2022-12-04 14:12:38 -05:00
|
|
|
}, {
|
|
|
|
combinationFilter: (p) => {
|
|
|
|
return (p.type === 'buffer' && p.encoding === 'undefined') ||
|
|
|
|
(p.type !== 'buffer' && p.encoding !== 'undefined');
|
|
|
|
},
|
2015-09-03 10:10:30 +02:00
|
|
|
});
|
|
|
|
|
2018-04-18 12:15:00 +02:00
|
|
|
function main({ n, search, encoding, type }) {
|
2019-12-13 18:43:41 +01:00
|
|
|
let aliceBuffer = fs.readFileSync(
|
2023-02-04 19:19:25 +01:00
|
|
|
path.resolve(__dirname, '../fixtures/alice.html'),
|
2016-03-02 13:38:23 -08:00
|
|
|
);
|
2015-09-03 10:10:30 +02:00
|
|
|
|
|
|
|
if (encoding === 'undefined') {
|
|
|
|
encoding = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (encoding === 'ucs2') {
|
2016-01-25 15:00:06 -08: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-25 15:00:06 -08:00
|
|
|
search = Buffer.from(Buffer.from(search).toString(), encoding);
|
2015-09-03 10:10:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bench.start();
|
2019-07-26 10:54:19 -05:00
|
|
|
for (let 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
|
|
|
}
|