Skip to content

Commit

Permalink
chore(benchmark): add qs for query-param (#3674)
Browse files Browse the repository at this point in the history
* chore(benchmark): add `qs` for query-param

* remove unused importing
  • Loading branch information
yusukebe authored Nov 14, 2024
1 parent 082862b commit 1e8ebe9
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 2 deletions.
218 changes: 217 additions & 1 deletion benchmarks/query-param/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion benchmarks/query-param/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
},
"license": "MIT",
"devDependencies": {
"@types/qs": "^6.9.17",
"tsx": "^3.12.2"
},
"dependencies": {
"fast-querystring": "^1.1.1",
"mitata": "^0.1.6"
"mitata": "^0.1.6",
"qs": "^6.13.0"
}
}
2 changes: 2 additions & 0 deletions benchmarks/query-param/src/bench.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { run, group, bench } from 'mitata'
import fastQuerystring from './fast-querystring.mts'
import hono from './hono.mts'
import qs from './qs.mts'
;[
{
url: 'http://example.com/?page=1',
Expand Down Expand Up @@ -36,6 +37,7 @@ import hono from './hono.mts'
group(JSON.stringify(data), () => {
bench('hono', () => hono(url, key))
bench('fastQuerystring', () => fastQuerystring(url, key))
bench('qs', () => qs(url, key))
})
})

Expand Down
12 changes: 12 additions & 0 deletions benchmarks/query-param/src/qs.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import qs from 'qs'

const getQueryStringFromURL = (url: string): string => {
const queryIndex = url.indexOf('?', 8)
const result = queryIndex !== -1 ? url.slice(queryIndex + 1) : ''
return result
}

export default (url, key?) => {
const data = qs.parse(getQueryStringFromURL(url))
return key !== undefined ? data[key] : data
}

0 comments on commit 1e8ebe9

Please sign in to comment.