generated from fastify/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 10
chore: replace benchmark with tinybench #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9627723
chore: replace benchmark with tinybench
Uzlopak cfbe8cf
Merge branch 'main' into replace-benchmark
Uzlopak 6af6647
extract benchmark into own folder
Uzlopak 3c48839
remove benchmark npm script
Uzlopak ab105ec
update benchmarks
Uzlopak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,139 @@ | ||
| import { Bench } from 'tinybench' | ||
| import { fastUri } from './index.js' | ||
| import { parse as uriJsParse, serialize as uriJsSerialize, resolve as uriJsResolve } from 'uri-js' | ||
|
|
||
| const base = 'uri://a/b/c/d;p?q' | ||
|
|
||
| const domain = 'https://example.com/foo#bar$fiz' | ||
| const ipv4 = '//10.10.10.10' | ||
| const ipv6 = '//[2001:db8::7]' | ||
| const urn = 'urn:foo:a123,456' | ||
| const urnuuid = 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6' | ||
|
|
||
| const { | ||
| parse: fastUriParse, | ||
| serialize: fastUriSerialize, | ||
| resolve: fastUriResolve | ||
| } = fastUri | ||
|
|
||
| // Initialization as there is a lot to parse at first | ||
| // eg: regexes | ||
| fastUriParse(domain) | ||
| uriJsParse(domain) | ||
|
|
||
| const benchFastUri = new Bench({ name: 'fast-uri benchmark' }) | ||
| const benchUriJs = new Bench({ name: 'uri-js benchmark' }) | ||
| const benchWHATWG = new Bench({ name: 'WHATWG URL benchmark' }) | ||
|
|
||
| benchFastUri.add('fast-uri: parse domain', function () { | ||
| fastUriParse(domain) | ||
| }) | ||
| benchUriJs.add('urijs: parse domain', function () { | ||
| uriJsParse(domain) | ||
| }) | ||
| benchWHATWG.add('WHATWG URL: parse domain', function () { | ||
| // eslint-disable-next-line | ||
| new URL(domain) | ||
| }) | ||
| benchFastUri.add('fast-uri: parse IPv4', function () { | ||
| fastUriParse(ipv4) | ||
| }) | ||
| benchUriJs.add('urijs: parse IPv4', function () { | ||
| uriJsParse(ipv4) | ||
| }) | ||
| benchFastUri.add('fast-uri: parse IPv6', function () { | ||
| fastUriParse(ipv6) | ||
| }) | ||
| benchUriJs.add('urijs: parse IPv6', function () { | ||
| uriJsParse(ipv6) | ||
| }) | ||
| benchFastUri.add('fast-uri: parse URN', function () { | ||
| fastUriParse(urn) | ||
| }) | ||
| benchUriJs.add('urijs: parse URN', function () { | ||
| uriJsParse(urn) | ||
| }) | ||
| benchWHATWG.add('WHATWG URL: parse URN', function () { | ||
| // eslint-disable-next-line | ||
| new URL(urn) | ||
| }) | ||
| benchFastUri.add('fast-uri: parse URN uuid', function () { | ||
| fastUriParse(urnuuid) | ||
| }) | ||
| benchUriJs.add('urijs: parse URN uuid', function () { | ||
| uriJsParse(urnuuid) | ||
| }) | ||
| benchFastUri.add('fast-uri: serialize uri', function () { | ||
| fastUriSerialize({ | ||
| scheme: 'uri', | ||
| userinfo: 'foo:bar', | ||
| host: 'example.com', | ||
| port: 1, | ||
| path: 'path', | ||
| query: 'query', | ||
| fragment: 'fragment' | ||
| }) | ||
| }) | ||
| benchUriJs.add('urijs: serialize uri', function () { | ||
| uriJsSerialize({ | ||
| scheme: 'uri', | ||
| userinfo: 'foo:bar', | ||
| host: 'example.com', | ||
| port: 1, | ||
| path: 'path', | ||
| query: 'query', | ||
| fragment: 'fragment' | ||
| }) | ||
| }) | ||
| benchFastUri.add('fast-uri: serialize long uri with dots', function () { | ||
| fastUriSerialize({ | ||
| scheme: 'uri', | ||
| userinfo: 'foo:bar', | ||
| host: 'example.com', | ||
| port: 1, | ||
| path: './a/./b/c/../.././d/../e/f/.././/', | ||
| query: 'query', | ||
| fragment: 'fragment' | ||
| }) | ||
| }) | ||
| benchUriJs.add('urijs: serialize long uri with dots', function () { | ||
| uriJsSerialize({ | ||
| scheme: 'uri', | ||
| userinfo: 'foo:bar', | ||
| host: 'example.com', | ||
| port: 1, | ||
| path: './a/./b/c/../.././d/../e/f/.././/', | ||
| query: 'query', | ||
| fragment: 'fragment' | ||
| }) | ||
| }) | ||
| benchFastUri.add('fast-uri: serialize IPv6', function () { | ||
| fastUriSerialize({ host: '2606:2800:220:1:248:1893:25c8:1946' }) | ||
| }) | ||
| benchUriJs.add('urijs: serialize IPv6', function () { | ||
| uriJsSerialize({ host: '2606:2800:220:1:248:1893:25c8:1946' }) | ||
| }) | ||
| benchFastUri.add('fast-uri: serialize ws', function () { | ||
| fastUriSerialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true }) | ||
| }) | ||
| benchUriJs.add('urijs: serialize ws', function () { | ||
| uriJsSerialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true }) | ||
| }) | ||
| benchFastUri.add('fast-uri: resolve', function () { | ||
| fastUriResolve(base, '../../../g') | ||
| }) | ||
| benchUriJs.add('urijs: resolve', function () { | ||
| uriJsResolve(base, '../../../g') | ||
| }) | ||
|
|
||
| await benchFastUri.run() | ||
| console.log(benchFastUri.name) | ||
| console.table(benchFastUri.table()) | ||
|
|
||
| await benchUriJs.run() | ||
| console.log(benchUriJs.name) | ||
| console.table(benchUriJs.table()) | ||
|
|
||
| await benchWHATWG.run() | ||
| console.log(benchWHATWG.name) | ||
| console.table(benchWHATWG.table()) | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.