mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-18 17:02:27 +02:00
Start using async/await where it makes sense
This commit is contained in:
parent
3d31a5f5d7
commit
7b8c087fdd
@ -3125,58 +3125,60 @@ FilterContainer.prototype.getFilterCount = function() {
|
|||||||
|
|
||||||
// action: 1=test, 2=record
|
// action: 1=test, 2=record
|
||||||
|
|
||||||
FilterContainer.prototype.benchmark = function(action) {
|
FilterContainer.prototype.benchmark = async function(action) {
|
||||||
µb.loadBenchmarkDataset().then(requests => {
|
const requests = await µb.loadBenchmarkDataset();
|
||||||
if ( Array.isArray(requests) === false || requests.length === 0 ) {
|
|
||||||
console.info('No requests found to benchmark');
|
if ( Array.isArray(requests) === false || requests.length === 0 ) {
|
||||||
return;
|
console.info('No requests found to benchmark');
|
||||||
}
|
return;
|
||||||
console.info(`Benchmarking staticNetFilteringEngine.matchString()...`);
|
}
|
||||||
const fctxt = µb.filteringContext.duplicate();
|
|
||||||
let expected, recorded;
|
console.info(`Benchmarking staticNetFilteringEngine.matchString()...`);
|
||||||
if ( action === 1 ) {
|
const fctxt = µb.filteringContext.duplicate();
|
||||||
try {
|
let expected, recorded;
|
||||||
expected = JSON.parse(
|
if ( action === 1 ) {
|
||||||
vAPI.localStorage.getItem('FilterContainer.benchmark.results')
|
try {
|
||||||
);
|
expected = JSON.parse(
|
||||||
} catch(ex) {
|
vAPI.localStorage.getItem('FilterContainer.benchmark.results')
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( action === 2 ) {
|
|
||||||
recorded = [];
|
|
||||||
}
|
|
||||||
const t0 = self.performance.now();
|
|
||||||
for ( let i = 0; i < requests.length; i++ ) {
|
|
||||||
const request = requests[i];
|
|
||||||
fctxt.setURL(request.url);
|
|
||||||
fctxt.setDocOriginFromURL(request.frameUrl);
|
|
||||||
fctxt.setType(request.cpt);
|
|
||||||
const r = this.matchString(fctxt);
|
|
||||||
if ( recorded !== undefined ) { recorded.push(r); }
|
|
||||||
if ( expected !== undefined && r !== expected[i] ) {
|
|
||||||
console.log('Mismatch with reference results:');
|
|
||||||
console.log(`\tExpected ${expected[i]}, got ${r}:`);
|
|
||||||
console.log(`\ttype=${fctxt.type}`);
|
|
||||||
console.log(`\turl=${fctxt.url}`);
|
|
||||||
console.log(`\tdocOrigin=${fctxt.getDocOrigin()}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const t1 = self.performance.now();
|
|
||||||
const dur = t1 - t0;
|
|
||||||
console.info(`Evaluated ${requests.length} requests in ${dur.toFixed(0)} ms`);
|
|
||||||
console.info(`\tAverage: ${(dur / requests.length).toFixed(3)} ms per request`);
|
|
||||||
if ( expected !== undefined ) {
|
|
||||||
console.info(`\tBlocked: ${expected.reduce((n,r)=>{return r===1?n+1:n;},0)}`);
|
|
||||||
console.info(`\tExcepted: ${expected.reduce((n,r)=>{return r===2?n+1:n;},0)}`);
|
|
||||||
}
|
|
||||||
if ( recorded !== undefined ) {
|
|
||||||
vAPI.localStorage.setItem(
|
|
||||||
'FilterContainer.benchmark.results',
|
|
||||||
JSON.stringify(recorded)
|
|
||||||
);
|
);
|
||||||
|
} catch(ex) {
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return 'ok';
|
if ( action === 2 ) {
|
||||||
|
recorded = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const t0 = self.performance.now();
|
||||||
|
for ( let i = 0; i < requests.length; i++ ) {
|
||||||
|
const request = requests[i];
|
||||||
|
fctxt.setURL(request.url);
|
||||||
|
fctxt.setDocOriginFromURL(request.frameUrl);
|
||||||
|
fctxt.setType(request.cpt);
|
||||||
|
const r = this.matchString(fctxt);
|
||||||
|
if ( recorded !== undefined ) { recorded.push(r); }
|
||||||
|
if ( expected !== undefined && r !== expected[i] ) {
|
||||||
|
console.log('Mismatch with reference results:');
|
||||||
|
console.log(`\tExpected ${expected[i]}, got ${r}:`);
|
||||||
|
console.log(`\ttype=${fctxt.type}`);
|
||||||
|
console.log(`\turl=${fctxt.url}`);
|
||||||
|
console.log(`\tdocOrigin=${fctxt.getDocOrigin()}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const t1 = self.performance.now();
|
||||||
|
const dur = t1 - t0;
|
||||||
|
|
||||||
|
console.info(`Evaluated ${requests.length} requests in ${dur.toFixed(0)} ms`);
|
||||||
|
console.info(`\tAverage: ${(dur / requests.length).toFixed(3)} ms per request`);
|
||||||
|
if ( expected !== undefined ) {
|
||||||
|
console.info(`\tBlocked: ${expected.reduce((n,r)=>{return r===1?n+1:n;},0)}`);
|
||||||
|
console.info(`\tExcepted: ${expected.reduce((n,r)=>{return r===2?n+1:n;},0)}`);
|
||||||
|
}
|
||||||
|
if ( recorded !== undefined ) {
|
||||||
|
vAPI.localStorage.setItem(
|
||||||
|
'FilterContainer.benchmark.results',
|
||||||
|
JSON.stringify(recorded)
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************-
|
/******************************************************************************-
|
||||||
|
Loading…
Reference in New Issue
Block a user