Skip to content

Commit 486f4c0

Browse files
committed
add benchmarks for equal
1 parent b17132f commit 486f4c0

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

benchmark/benchmark.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Bench } from 'tinybench'
22
import { fastUri } from '../index.js'
3-
import { parse as uriJsParse, serialize as uriJsSerialize, resolve as uriJsResolve } from 'uri-js'
3+
import { parse as uriJsParse, serialize as uriJsSerialize, resolve as uriJsResolve, equal as uriJsEqual } from 'uri-js'
44

55
const base = 'uri://a/b/c/d;p?q'
66

@@ -19,7 +19,8 @@ const urnuuidComponent = {
1919
const {
2020
parse: fastUriParse,
2121
serialize: fastUriSerialize,
22-
resolve: fastUriResolve
22+
resolve: fastUriResolve,
23+
equal: fastUriEqual,
2324
} = fastUri
2425

2526
// Initialization as there is a lot to parse at first
@@ -138,6 +139,13 @@ benchUriJs.add('urijs: resolve', function () {
138139
uriJsResolve(base, '../../../g')
139140
})
140141

142+
benchFastUri.add('fast-uri: equal', function () {
143+
fastUriEqual('example://a/b/c/%7Bfoo%7D', 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d')
144+
})
145+
benchUriJs.add('urijs: equal', function () {
146+
uriJsEqual('example://a/b/c/%7Bfoo%7D', 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d')
147+
})
148+
141149
await benchFastUri.run()
142150
console.log(benchFastUri.name)
143151
console.table(benchFastUri.table())

benchmark/equal.mjs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Bench } from 'tinybench'
2+
import { fastUri } from '../index.js'
3+
4+
const {
5+
equal: fastUriEqual,
6+
parse: fastUriParse,
7+
} = fastUri
8+
9+
const stringA = 'example://a/b/c/%7Bfoo%7D'
10+
const stringB = 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d'
11+
12+
const componentA = fastUriParse(stringA)
13+
const componentB = fastUriParse(stringB)
14+
15+
const benchFastUri = new Bench({ name: 'fast-uri equal' })
16+
17+
benchFastUri.add('equal string with string', function () {
18+
fastUriEqual(stringA, stringA)
19+
})
20+
21+
benchFastUri.add('equal component with component', function () {
22+
fastUriEqual(componentA, componentA)
23+
})
24+
25+
benchFastUri.add('equal component with string', function () {
26+
fastUriEqual(componentA, stringA)
27+
})
28+
29+
benchFastUri.add('equal string with component', function () {
30+
fastUriEqual(stringA, componentA)
31+
})
32+
33+
benchFastUri.add('not equal string with string', function () {
34+
fastUriEqual(stringA, stringB)
35+
})
36+
37+
benchFastUri.add('not equal component with component', function () {
38+
fastUriEqual(componentA, componentB)
39+
})
40+
41+
benchFastUri.add('not equal component with string', function () {
42+
fastUriEqual(componentA, stringB)
43+
})
44+
45+
benchFastUri.add('not equal string with component', function () {
46+
fastUriEqual(stringA, componentB)
47+
})
48+
49+
await benchFastUri.run()
50+
console.log(benchFastUri.name)
51+
console.table(benchFastUri.table())

0 commit comments

Comments
 (0)