mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-02 00:42:45 +01:00
Add benchmark method to cosmetic filtering engine
To measure retrieval of site-specific selectors. From uBO's own dev console: µBlock.cosmeticFilteringEngine.benchmark();
This commit is contained in:
parent
fbb4950b5d
commit
1e40f50eb3
@ -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();
|
||||
|
||||
/******************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user