Skip to content

Commit

Permalink
Implement hosts-only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mjethani committed Aug 5, 2021
1 parent dccc7ba commit 8dfb8ca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/adblocker-benchmarks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ ifeq ($(SHOW_MEMORY), 1)
run_options := $(run_options) --memory
endif

ifeq ($(HOSTS_ONLY), 1)
run_options := $(run_options) --hosts-only
endif

.PHONY: all clean deps run ubo-core adblockpluscore tsurlfilter-node adblock-rs brave cliqz cliqz-compression ublock adblockplus tsurlfilter tldts url min

all: deps run
Expand Down
19 changes: 18 additions & 1 deletion packages/adblocker-benchmarks/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,27 @@ function isSupportedUrl(url) {
);
}

function looksLikeHostFilter(raw) {
// https://en.wikipedia.org/wiki/Hostname#Syntax
// The colon is included for the port number. e.g. ||localhost:8080^ could
// also be a host filter. The brackets are included for IPv6 addresses.
// e.g. ||[::1]^ could be a host filter. This also covers filters like
// ||localhost/ and ||localhost:
return /^(@@)?\|\|[a-z0-9.:[\]-]+[/:^]$/i.test(raw);
}

function loadLists() {
return fs.readFileSync(path.resolve(__dirname, './easylist.txt'), { encoding: 'utf-8' });
}

function filterLists(rawLists) {
if (FLAGS.includes('--hosts-only')) {
rawLists = rawLists.split(/\n/g).filter(looksLikeHostFilter).join('\n');
}

return rawLists;
}

function wait(milliseconds) {
return new Promise(resolve => {
setTimeout(resolve, milliseconds);
Expand All @@ -109,7 +126,7 @@ async function memoryUsage(base = { heapUsed: 0, heapTotal: 0, }) {
}

async function main() {
const rawLists = loadLists();
const rawLists = filterLists(loadLists());

let moduleId;
switch (ENGINE) {
Expand Down

0 comments on commit 8dfb8ca

Please sign in to comment.