Skip to content

Commit 1e40f50

Browse files
committed
Add benchmark method to cosmetic filtering engine
To measure retrieval of site-specific selectors. From uBO's own dev console: µBlock.cosmeticFilteringEngine.benchmark();
1 parent fbb4950 commit 1e40f50

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/js/cosmetic-filtering.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,45 @@ FilterContainer.prototype.getFilterCount = function() {
14101410

14111411
/******************************************************************************/
14121412

1413+
FilterContainer.prototype.benchmark = function() {
1414+
µb.loadBenchmarkDataset().then(requests => {
1415+
if ( Array.isArray(requests) === false || requests.length === 0 ) {
1416+
console.info('No requests found to benchmark');
1417+
return;
1418+
}
1419+
console.info(`Benchmarking cosmeticFilteringEngine.matchString()...`);
1420+
const details = {
1421+
tabId: undefined,
1422+
frameId: undefined,
1423+
hostname: '',
1424+
domain: '',
1425+
entity: '',
1426+
};
1427+
const options = {
1428+
noCosmeticFiltering: false,
1429+
noGenericCosmeticFiltering: false,
1430+
};
1431+
let count = 0;
1432+
const t0 = self.performance.now();
1433+
for ( let i = 0; i < requests.length; i++ ) {
1434+
const request = requests[i];
1435+
if ( request.cpt !== 'document' ) { continue; }
1436+
count += 1;
1437+
details.hostname = µb.URI.hostnameFromURI(request.url);
1438+
details.domain = µb.URI.domainFromHostname(details.hostname);
1439+
details.entity = µb.URI.entityFromDomain(details.domain);
1440+
void this.retrieveSpecificSelectors(details, options);
1441+
}
1442+
const t1 = self.performance.now();
1443+
const dur = t1 - t0;
1444+
console.info(`Evaluated ${count} requests in ${dur.toFixed(0)} ms`);
1445+
console.info(`\tAverage: ${(dur / count).toFixed(3)} ms per request`);
1446+
});
1447+
return 'ok';
1448+
};
1449+
1450+
/******************************************************************************/
1451+
14131452
return new FilterContainer();
14141453

14151454
/******************************************************************************/

0 commit comments

Comments
 (0)