1
0
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:
Raymond Hill 2019-05-22 19:23:04 -04:00
parent 3d31a5f5d7
commit 7b8c087fdd
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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';
};
/******************************************************************************-