-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update publicsuffix lists * Move benchmark in its own repository
- Loading branch information
Showing
9 changed files
with
936 additions
and
1,212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
all: run | ||
|
||
requests.json: | ||
curl https://cdn.cliqz.com/adblocking/requests_top500.json.gz | gunzip > requests.json | ||
|
||
run: requests.json | ||
NODE_ENV=production node benchmark.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env node | ||
|
||
const { URL } = require('url'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const tldtsExperimental = require(path.resolve( | ||
__dirname, | ||
'../dist/tldts-experimental.umd.min.js', | ||
)); | ||
const tldtsDefault = require(path.resolve( | ||
__dirname, | ||
'../dist/tldts.umd.min.js', | ||
)); | ||
|
||
function bench(title, tldts, inputs) { | ||
console.log(`* Start: ${title}`); | ||
const t0 = Date.now(); | ||
for (let i = 0; i < inputs.length; i += 1) { | ||
tldts.parse(inputs[i]); | ||
tldts.parse(inputs[i]); | ||
tldts.parse(inputs[i]); | ||
tldts.parse(inputs[i]); | ||
tldts.parse(inputs[i]); | ||
} | ||
const total = Date.now() - t0; | ||
console.log(` - ${total / 5} ms`); | ||
console.log(` - ${total / inputs.length / 5} ms per input`); | ||
console.log( | ||
` - ${Math.floor(1000 / (total / inputs.length / 5))} calls per second`, | ||
); | ||
} | ||
|
||
function main() { | ||
const urls = [ | ||
...new Set( | ||
fs | ||
.readFileSync(path.resolve(__dirname, './requests.json'), { | ||
encoding: 'utf-8', | ||
}) | ||
.split(/[\n\r]+/g) | ||
.map(JSON.parse) | ||
.map(({ url }) => url), | ||
), | ||
]; | ||
console.log('urls', urls.length); | ||
|
||
const hostnames = [...new Set(urls.map(url => new URL(url).hostname))]; | ||
console.log('Hosts', hostnames.length); | ||
|
||
bench('tldts URLs', tldtsDefault, urls); | ||
bench('tldts-experimental URLs', tldtsExperimental, urls); | ||
bench('tldts hostnames', tldtsDefault, hostnames); | ||
bench('tldts-experimental hostnames', tldtsExperimental, hostnames); | ||
} | ||
|
||
main(); |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.