-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: add simple parse and test benchmarks for URLPattern
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const { URLPattern } = require('url'); | ||
const { ok } = require('assert'); | ||
|
||
const tests = [ | ||
'https://(sub.)?example(.com/)foo', | ||
{ 'hostname': 'xn--caf-dma.com' }, | ||
{ 'pathname': '/foo', 'search': 'bar', 'hash': 'baz', | ||
'baseURL': 'https://example.com:8080' }, | ||
{ 'pathname': '/([[a-z]--a])' }, | ||
]; | ||
|
||
const bench = common.createBenchmark(main, { | ||
pattern: tests.map(JSON.stringify), | ||
n: [1e5], | ||
}); | ||
|
||
function main({ pattern, n }) { | ||
const inputPattern = JSON.parse(pattern); | ||
let deadcode = null; | ||
bench.start(); | ||
for (let i = 0; i < n; i += 1) { | ||
deadcode = new URLPattern(inputPattern); | ||
} | ||
bench.end(n); | ||
ok(deadcode); | ||
} |
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,30 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const { URLPattern } = require('url'); | ||
const { notStrictEqual } = require('assert'); | ||
|
||
const tests = [ | ||
'https://(sub.)?example(.com/)foo', | ||
{ 'hostname': 'xn--caf-dma.com' }, | ||
{ 'pathname': '/foo', 'search': 'bar', 'hash': 'baz', | ||
'baseURL': 'https://example.com:8080' }, | ||
{ 'pathname': '/([[a-z]--a])' }, | ||
]; | ||
|
||
const bench = common.createBenchmark(main, { | ||
pattern: tests.map(JSON.stringify), | ||
n: [1e5], | ||
}); | ||
|
||
function main({ pattern, n }) { | ||
const inputPattern = JSON.parse(pattern); | ||
const urlpattern = new URLPattern(inputPattern); | ||
|
||
let deadcode = undefined; | ||
bench.start(); | ||
for (let i = 0; i < n; i += 1) { | ||
deadcode = urlpattern.test('https://sub.example.com/foo'); | ||
} | ||
bench.end(n); | ||
notStrictEqual(deadcode, undefined); // We don't care if it is true or false. | ||
} |