Skip to content

Commit

Permalink
Add benchmark method to cosmetic filtering engine
Browse files Browse the repository at this point in the history
To measure retrieval of site-specific selectors. From
uBO's own dev console:

    µBlock.cosmeticFilteringEngine.benchmark();
  • Loading branch information
gorhill committed May 12, 2019
1 parent fbb4950 commit 1e40f50
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/js/cosmetic-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,45 @@ FilterContainer.prototype.getFilterCount = function() {

/******************************************************************************/

FilterContainer.prototype.benchmark = function() {
µb.loadBenchmarkDataset().then(requests => {
if ( Array.isArray(requests) === false || requests.length === 0 ) {
console.info('No requests found to benchmark');
return;
}
console.info(`Benchmarking cosmeticFilteringEngine.matchString()...`);
const details = {
tabId: undefined,
frameId: undefined,
hostname: '',
domain: '',
entity: '',
};
const options = {
noCosmeticFiltering: false,
noGenericCosmeticFiltering: false,
};
let count = 0;
const t0 = self.performance.now();
for ( let i = 0; i < requests.length; i++ ) {
const request = requests[i];
if ( request.cpt !== 'document' ) { continue; }
count += 1;
details.hostname = µb.URI.hostnameFromURI(request.url);
details.domain = µb.URI.domainFromHostname(details.hostname);
details.entity = µb.URI.entityFromDomain(details.domain);
void this.retrieveSpecificSelectors(details, options);
}
const t1 = self.performance.now();
const dur = t1 - t0;
console.info(`Evaluated ${count} requests in ${dur.toFixed(0)} ms`);
console.info(`\tAverage: ${(dur / count).toFixed(3)} ms per request`);
});
return 'ok';
};

/******************************************************************************/

return new FilterContainer();

/******************************************************************************/
Expand Down

0 comments on commit 1e40f50

Please sign in to comment.