diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index dc2217dcb..abd22150e 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -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(); /******************************************************************************/