Skip to content

Commit 509dd94

Browse files
authored
chore: replace benchmark with tinybench (#143)
* chore: replace benchmark with tinybench * extract benchmark into own folder * remove benchmark npm script * update benchmarks
1 parent 7a16582 commit 509dd94

5 files changed

Lines changed: 193 additions & 152 deletions

File tree

README.md

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,43 @@ fast-uri supports inserting custom [scheme](http://en.wikipedia.org/wiki/URI_sch
9494
## Benchmarks
9595

9696
```
97-
fast-uri: parse domain x 1,306,864 ops/sec ±0.31% (100 runs sampled)
98-
urijs: parse domain x 483,001 ops/sec ±0.09% (99 runs sampled)
99-
WHATWG URL: parse domain x 862,461 ops/sec ±0.18% (97 runs sampled)
100-
fast-uri: parse IPv4 x 2,381,452 ops/sec ±0.26% (96 runs sampled)
101-
urijs: parse IPv4 x 384,705 ops/sec ±0.34% (99 runs sampled)
102-
WHATWG URL: parse IPv4 NOT SUPPORTED
103-
fast-uri: parse IPv6 x 923,519 ops/sec ±0.09% (100 runs sampled)
104-
urijs: parse IPv6 x 289,070 ops/sec ±0.07% (95 runs sampled)
105-
WHATWG URL: parse IPv6 NOT SUPPORTED
106-
fast-uri: parse URN x 2,596,395 ops/sec ±0.42% (98 runs sampled)
107-
urijs: parse URN x 1,152,412 ops/sec ±0.09% (97 runs sampled)
108-
WHATWG URL: parse URN x 1,183,307 ops/sec ±0.38% (100 runs sampled)
109-
fast-uri: parse URN uuid x 1,666,861 ops/sec ±0.10% (98 runs sampled)
110-
urijs: parse URN uuid x 852,724 ops/sec ±0.17% (95 runs sampled)
111-
WHATWG URL: parse URN uuid NOT SUPPORTED
112-
fast-uri: serialize uri x 1,741,499 ops/sec ±0.57% (95 runs sampled)
113-
urijs: serialize uri x 389,014 ops/sec ±0.28% (93 runs sampled)
114-
fast-uri: serialize IPv6 x 441,095 ops/sec ±0.37% (97 runs sampled)
115-
urijs: serialize IPv6 x 255,443 ops/sec ±0.58% (94 runs sampled)
116-
fast-uri: serialize ws x 1,448,667 ops/sec ±0.25% (97 runs sampled)
117-
urijs: serialize ws x 352,884 ops/sec ±0.08% (96 runs sampled)
118-
fast-uri: resolve x 340,084 ops/sec ±0.98% (98 runs sampled)
119-
urijs: resolve x 225,759 ops/sec ±0.37% (95 runs sampled)
97+
fast-uri benchmark
98+
┌─────────┬──────────────────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
99+
│ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
100+
├─────────┼──────────────────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
101+
│ 0 │ 'fast-uri: parse domain' │ '966.56 ± 0.76%' │ '888.00 ± 10.00' │ '1102014 ± 0.01%' │ '1126126 ± 12826' │ 1034600 │
102+
│ 1 │ 'fast-uri: parse IPv4' │ '697.95 ± 0.44%' │ '625.00 ± 8.00' │ '1562449 ± 0.01%' │ '1600000 ± 20221' │ 1432761 │
103+
│ 2 │ 'fast-uri: parse IPv6' │ '1319.9 ± 2.85%' │ '1180.0 ± 13.00' │ '834310 ± 0.02%' │ '847458 ± 9235' │ 757626 │
104+
│ 3 │ 'fast-uri: parse URN' │ '690.06 ± 0.23%' │ '636.00 ± 10.00' │ '1542937 ± 0.01%' │ '1572327 ± 25117' │ 1449157 │
105+
│ 4 │ 'fast-uri: parse URN uuid' │ '1047.2 ± 3.37%' │ '936.00 ± 18.00' │ '1050646 ± 0.02%' │ '1068376 ± 20158' │ 954915 │
106+
│ 5 │ 'fast-uri: serialize uri' │ '1138.6 ± 4.45%' │ '1005.0 ± 13.00' │ '973816 ± 0.02%' │ '995025 ± 12707' │ 878304 │
107+
│ 6 │ 'fast-uri: serialize long uri with dots' │ '1773.7 ± 0.36%' │ '1634.0 ± 14.00' │ '601087 ± 0.02%' │ '611995 ± 5289' │ 563798 │
108+
│ 7 │ 'fast-uri: serialize IPv6' │ '2532.7 ± 0.46%' │ '2334.0 ± 19.00' │ '421133 ± 0.03%' │ '428449 ± 3460' │ 394843 │
109+
│ 8 │ 'fast-uri: serialize ws' │ '1019.8 ± 2.06%' │ '926.00 ± 9.00' │ '1062555 ± 0.02%' │ '1079914 ± 10395' │ 980564 │
110+
│ 9 │ 'fast-uri: resolve' │ '2169.3 ± 0.49%' │ '1994.0 ± 21.00' │ '492756 ± 0.03%' │ '501505 ± 5338' │ 460987 │
111+
└─────────┴──────────────────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
112+
uri-js benchmark
113+
┌─────────┬───────────────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
114+
│ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
115+
├─────────┼───────────────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
116+
│ 0 │ 'urijs: parse domain' │ '3618.3 ± 0.43%' │ '3314.0 ± 33.00' │ '294875 ± 0.04%' │ '301750 ± 2975' │ 276375 │
117+
│ 1 │ 'urijs: parse IPv4' │ '4024.1 ± 0.41%' │ '3751.0 ± 25.00' │ '261981 ± 0.04%' │ '266596 ± 1789' │ 248506 │
118+
│ 2 │ 'urijs: parse IPv6' │ '5417.2 ± 0.46%' │ '4968.0 ± 43.00' │ '196023 ± 0.05%' │ '201288 ± 1727' │ 184598 │
119+
│ 3 │ 'urijs: parse URN' │ '1324.2 ± 0.23%' │ '1229.0 ± 17.00' │ '801535 ± 0.02%' │ '813670 ± 11413' │ 755185 │
120+
│ 4 │ 'urijs: parse URN uuid' │ '1822.0 ± 3.08%' │ '1655.0 ± 15.00' │ '594433 ± 0.02%' │ '604230 ± 5427' │ 548843 │
121+
│ 5 │ 'urijs: serialize uri' │ '4196.8 ± 0.36%' │ '3908.0 ± 27.00' │ '251146 ± 0.04%' │ '255885 ± 1756' │ 238276 │
122+
│ 6 │ 'urijs: serialize long uri with dots' │ '8331.0 ± 1.30%' │ '7658.0 ± 72.00' │ '126440 ± 0.07%' │ '130582 ± 1239' │ 120034 │
123+
│ 7 │ 'urijs: serialize IPv6' │ '5685.5 ± 0.30%' │ '5366.0 ± 33.00' │ '182632 ± 0.05%' │ '186359 ± 1153' │ 175886 │
124+
│ 8 │ 'urijs: serialize ws' │ '4159.3 ± 0.20%' │ '3899.0 ± 28.00' │ '250459 ± 0.04%' │ '256476 ± 1855' │ 240423 │
125+
│ 9 │ 'urijs: resolve' │ '6729.9 ± 0.39%' │ '6261.0 ± 37.00' │ '156361 ± 0.06%' │ '159719 ± 949' │ 148591 │
126+
└─────────┴───────────────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
127+
WHATWG URL benchmark
128+
┌─────────┬────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
129+
│ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
130+
├─────────┼────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
131+
│ 0 │ 'WHATWG URL: parse domain' │ '475.22 ± 0.20%' │ '444.00 ± 5.00' │ '2217599 ± 0.01%' │ '2252252 ± 25652' │ 2104289 │
132+
│ 1 │ 'WHATWG URL: parse URN' │ '384.78 ± 0.85%' │ '350.00 ± 5.00' │ '2809071 ± 0.01%' │ '2857143 ± 41408' │ 2598885 │
133+
└─────────┴────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
120134
```
121135

122136
## TODO

benchmark.js

Lines changed: 0 additions & 127 deletions
This file was deleted.

benchmark/benchmark.mjs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import { Bench } from 'tinybench'
2+
import { fastUri } from '../index.js'
3+
import { parse as uriJsParse, serialize as uriJsSerialize, resolve as uriJsResolve } from 'uri-js'
4+
5+
const base = 'uri://a/b/c/d;p?q'
6+
7+
const domain = 'https://example.com/foo#bar$fiz'
8+
const ipv4 = '//10.10.10.10'
9+
const ipv6 = '//[2001:db8::7]'
10+
const urn = 'urn:foo:a123,456'
11+
const urnuuid = 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
12+
13+
const {
14+
parse: fastUriParse,
15+
serialize: fastUriSerialize,
16+
resolve: fastUriResolve
17+
} = fastUri
18+
19+
// Initialization as there is a lot to parse at first
20+
// eg: regexes
21+
fastUriParse(domain)
22+
uriJsParse(domain)
23+
24+
const benchFastUri = new Bench({ name: 'fast-uri benchmark' })
25+
const benchUriJs = new Bench({ name: 'uri-js benchmark' })
26+
const benchWHATWG = new Bench({ name: 'WHATWG URL benchmark' })
27+
28+
benchFastUri.add('fast-uri: parse domain', function () {
29+
fastUriParse(domain)
30+
})
31+
benchUriJs.add('urijs: parse domain', function () {
32+
uriJsParse(domain)
33+
})
34+
benchWHATWG.add('WHATWG URL: parse domain', function () {
35+
// eslint-disable-next-line
36+
new URL(domain)
37+
})
38+
benchFastUri.add('fast-uri: parse IPv4', function () {
39+
fastUriParse(ipv4)
40+
})
41+
benchUriJs.add('urijs: parse IPv4', function () {
42+
uriJsParse(ipv4)
43+
})
44+
benchFastUri.add('fast-uri: parse IPv6', function () {
45+
fastUriParse(ipv6)
46+
})
47+
benchUriJs.add('urijs: parse IPv6', function () {
48+
uriJsParse(ipv6)
49+
})
50+
benchFastUri.add('fast-uri: parse URN', function () {
51+
fastUriParse(urn)
52+
})
53+
benchUriJs.add('urijs: parse URN', function () {
54+
uriJsParse(urn)
55+
})
56+
benchWHATWG.add('WHATWG URL: parse URN', function () {
57+
// eslint-disable-next-line
58+
new URL(urn)
59+
})
60+
benchFastUri.add('fast-uri: parse URN uuid', function () {
61+
fastUriParse(urnuuid)
62+
})
63+
benchUriJs.add('urijs: parse URN uuid', function () {
64+
uriJsParse(urnuuid)
65+
})
66+
benchFastUri.add('fast-uri: serialize uri', function () {
67+
fastUriSerialize({
68+
scheme: 'uri',
69+
userinfo: 'foo:bar',
70+
host: 'example.com',
71+
port: 1,
72+
path: 'path',
73+
query: 'query',
74+
fragment: 'fragment'
75+
})
76+
})
77+
benchUriJs.add('urijs: serialize uri', function () {
78+
uriJsSerialize({
79+
scheme: 'uri',
80+
userinfo: 'foo:bar',
81+
host: 'example.com',
82+
port: 1,
83+
path: 'path',
84+
query: 'query',
85+
fragment: 'fragment'
86+
})
87+
})
88+
benchFastUri.add('fast-uri: serialize long uri with dots', function () {
89+
fastUriSerialize({
90+
scheme: 'uri',
91+
userinfo: 'foo:bar',
92+
host: 'example.com',
93+
port: 1,
94+
path: './a/./b/c/../.././d/../e/f/.././/',
95+
query: 'query',
96+
fragment: 'fragment'
97+
})
98+
})
99+
benchUriJs.add('urijs: serialize long uri with dots', function () {
100+
uriJsSerialize({
101+
scheme: 'uri',
102+
userinfo: 'foo:bar',
103+
host: 'example.com',
104+
port: 1,
105+
path: './a/./b/c/../.././d/../e/f/.././/',
106+
query: 'query',
107+
fragment: 'fragment'
108+
})
109+
})
110+
benchFastUri.add('fast-uri: serialize IPv6', function () {
111+
fastUriSerialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
112+
})
113+
benchUriJs.add('urijs: serialize IPv6', function () {
114+
uriJsSerialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
115+
})
116+
benchFastUri.add('fast-uri: serialize ws', function () {
117+
fastUriSerialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
118+
})
119+
benchUriJs.add('urijs: serialize ws', function () {
120+
uriJsSerialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
121+
})
122+
benchFastUri.add('fast-uri: resolve', function () {
123+
fastUriResolve(base, '../../../g')
124+
})
125+
benchUriJs.add('urijs: resolve', function () {
126+
uriJsResolve(base, '../../../g')
127+
})
128+
129+
await benchFastUri.run()
130+
console.log(benchFastUri.name)
131+
console.table(benchFastUri.table())
132+
133+
await benchUriJs.run()
134+
console.log(benchUriJs.name)
135+
console.table(benchUriJs.table())
136+
137+
await benchWHATWG.run()
138+
console.log(benchWHATWG.name)
139+
console.table(benchWHATWG.table())

benchmark/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "benchmark",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"private": true,
7+
"scripts": {
8+
"bench": "node benchmark.mjs"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"tinybench": "^5.0.0",
15+
"uri-js": "^4.4.1"
16+
}
17+
}

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
}
4747
],
4848
"scripts": {
49-
"bench": "node benchmark.js",
5049
"lint": "eslint",
5150
"lint:fix": "eslint --fix",
5251
"test": "npm run test:unit && npm run test:typescript",
@@ -57,7 +56,6 @@
5756
"devDependencies": {
5857
"@fastify/pre-commit": "^2.1.0",
5958
"ajv": "^8.16.0",
60-
"benchmark": "^2.1.4",
6159
"eslint": "^9.17.0",
6260
"neostandard": "^0.12.0",
6361
"tape": "^5.8.1",

0 commit comments

Comments
 (0)