Add median cost output to dig-snfe

This commit is contained in:
Raymond Hill 2021-08-29 08:58:20 -04:00
parent 19fb513d52
commit d41f28fcd8
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 17 additions and 5 deletions

View File

@ -2,7 +2,7 @@
run_options := $(filter-out $@,$(MAKECMDGOALS))
.PHONY: all clean test lint chromium firefox npm dig \
compare maxcost mincost modifiers record wasm
compare maxcost medcost mincost modifiers record wasm
sources := $(wildcard src/* src/*/* src/*/*/* src/*/*/*/*)
platform := $(wildcard platform/* platform/*/*)
@ -65,6 +65,8 @@ compare:
@echo
maxcost:
@echo
medcost:
@echo
mincost:
@echo
modifiers:

View File

@ -41,11 +41,12 @@ import { enableWASM, StaticNetFilteringEngine } from './index.js';
const FLAGS = process.argv.slice(2);
const COMPARE = FLAGS.includes('compare');
const MAXCOST = FLAGS.includes('maxcost');
const MEDCOST = FLAGS.includes('medcost');
const MINCOST = FLAGS.includes('mincost');
const MODIFIERS = FLAGS.includes('modifiers');
const RECORD = FLAGS.includes('record');
const WASM = FLAGS.includes('wasm');
const NEED_RESULTS = COMPARE || MAXCOST || MINCOST || RECORD;
const NEED_RESULTS = COMPARE || MAXCOST || MEDCOST || MINCOST || RECORD;
// This maps puppeteer types to WebRequest types
const WEBREQUEST_OPTIONS = {
@ -153,8 +154,14 @@ async function matchRequests(engine, requests) {
write('data/snfe.maxcost.json', JSON.stringify(costly, null, 2));
}
if ( MEDCOST ) {
const median = results.length >>> 1;
const costly = results.slice().sort((a,b) => b[1].t - a[1].t).slice(median - 500, median + 500);
write('data/snfe.medcost.json', JSON.stringify(costly, null, 2));
}
if ( MINCOST ) {
const costly = results.slice().sort((a,b) => a[1].t - b[1].t).slice(0, 1000);
const costly = results.slice().sort((a,b) => b[1].t - a[1].t).slice(-1000);
write('data/snfe.mincost.json', JSON.stringify(costly, null, 2));
}
}

View File

@ -21,10 +21,13 @@
"adblock",
"trie"
],
"author": "Raymond Hill",
"author": "Raymond Hill (https://github.com/gorhill)",
"license": "GPL-3.0-or-later",
"contributors": [
"Manish Jethani <code@manishjethani.io>"
],
"bugs": {
"url": "https://github.com/gorhill/uBlock/issues"
"url": "https://github.com/uBlockOrigin/uBlock-issues/issues"
},
"homepage": "https://github.com/gorhill/uBlock#readme",
"engines": {