mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01:00
Start using async/await where it makes sense
This commit is contained in:
parent
3d31a5f5d7
commit
7b8c087fdd
@ -3125,12 +3125,14 @@ FilterContainer.prototype.getFilterCount = function() {
|
||||
|
||||
// action: 1=test, 2=record
|
||||
|
||||
FilterContainer.prototype.benchmark = function(action) {
|
||||
µb.loadBenchmarkDataset().then(requests => {
|
||||
FilterContainer.prototype.benchmark = async function(action) {
|
||||
const requests = await µb.loadBenchmarkDataset();
|
||||
|
||||
if ( Array.isArray(requests) === false || requests.length === 0 ) {
|
||||
console.info('No requests found to benchmark');
|
||||
return;
|
||||
}
|
||||
|
||||
console.info(`Benchmarking staticNetFilteringEngine.matchString()...`);
|
||||
const fctxt = µb.filteringContext.duplicate();
|
||||
let expected, recorded;
|
||||
@ -3145,6 +3147,7 @@ FilterContainer.prototype.benchmark = function(action) {
|
||||
if ( action === 2 ) {
|
||||
recorded = [];
|
||||
}
|
||||
|
||||
const t0 = self.performance.now();
|
||||
for ( let i = 0; i < requests.length; i++ ) {
|
||||
const request = requests[i];
|
||||
@ -3163,6 +3166,7 @@ FilterContainer.prototype.benchmark = function(action) {
|
||||
}
|
||||
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 ) {
|
||||
@ -3175,8 +3179,6 @@ FilterContainer.prototype.benchmark = function(action) {
|
||||
JSON.stringify(recorded)
|
||||
);
|
||||
}
|
||||
});
|
||||
return 'ok';
|
||||
};
|
||||
|
||||
/******************************************************************************-
|
||||
|
Loading…
Reference in New Issue
Block a user