Skip to content

Commit

Permalink
docs: add more benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Sep 8, 2022
1 parent 405da62 commit c2b2fbf
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 22 deletions.
47 changes: 25 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,18 @@ console.log(qs.stringify({ foo: ['bar', 'baz'] }))
╔═════════════════════════════════════════╤═════════╤═══════════════════╤═══════════╗
║ Slower tests │ Samples │ Result │ Tolerance ║
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢
║ qs │ 10000 │ 290743.91 op/sec │ ± 1.87 % ║
║ query-string │ 1500 │ 333025.25 op/sec │ ± 0.98 % ║
║ querystringify │ 10000 │ 430382.40 op/sec │ ± 1.95 % ║
║ @aws-sdk/querystring-parser │ 3000 │ 452331.29 op/sec │ ± 0.87 % ║
║ URLSearchParams-with-Object.fromEntries │ 2000 │ 862635.26 op/sec │ ± 0.87 % ║
║ URLSearchParams-with-construct │ 10000 │ 1216331.19 op/sec │ ± 3.19 % ║
║ node:querystring │ 10000 │ 1453849.93 op/sec │ ± 4.50 % ║
║ qs │ 10000 │ 302595.31 op/sec │ ± 1.22 % ║
║ query-string │ 9500 │ 334820.82 op/sec │ ± 0.99 % ║
║ querystringify │ 1000 │ 437899.50 op/sec │ ± 0.73 % ║
║ @aws-sdk/querystring-parser │ 1000 │ 454836.96 op/sec │ ± 0.69 % ║
║ URLSearchParams-with-Object.fromEntries │ 1500 │ 849572.92 op/sec │ ± 0.89 % ║
║ URLSearchParams-with-construct │ 10000 │ 1190835.28 op/sec │ ± 3.22 % ║
║ node:querystring │ 10000 │ 1384717.43 op/sec │ ± 2.99 % ║
║ querystringparser │ 3500 │ 1735544.65 op/sec │ ± 0.95 % ║
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢
║ Fastest test │ Samples │ Result │ Tolerance ║
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢
║ fast-querystring │ 10000 │ 2047629.50 op/sec │ ± 3.72 % ║
║ fast-querystring │ 10000 │ 2023187.35 op/sec │ ± 2.67 % ║
╚═════════════════════════════════════════╧═════════╧═══════════════════╧═══════════╝
```

Expand All @@ -67,18 +68,20 @@ console.log(qs.stringify({ foo: ['bar', 'baz'] }))
```
> node benchmark/stringify.mjs
╔════════════════════════════╤═════════╤═══════════════════╤═══════════╗
║ Slower tests │ Samples │ Result │ Tolerance ║
╟────────────────────────────┼─────────┼───────────────────┼───────────╢
║ query-string │ 10000 │ 284130.63 op/sec │ ± 1.62 % ║
║ qs │ 10000 │ 334799.48 op/sec │ ± 1.93 % ║
║ http-querystring-stringify │ 10000 │ 482642.49 op/sec │ ± 1.72 % ║
║ URLSearchParams │ 10000 │ 587274.65 op/sec │ ± 1.88 % ║
║ querystringify │ 10000 │ 753960.35 op/sec │ ± 2.20 % ║
║ node:querystring │ 10000 │ 1796993.95 op/sec │ ± 5.34 % ║
╟────────────────────────────┼─────────┼───────────────────┼───────────╢
║ Fastest test │ Samples │ Result │ Tolerance ║
╟────────────────────────────┼─────────┼───────────────────┼───────────╢
║ fast-querystring │ 10000 │ 2051022.89 op/sec │ ± 4.52 % ║
╚════════════════════════════╧═════════╧═══════════════════╧═══════════╝
╔══════════════════════════════╤═════════╤═══════════════════╤═══════════╗
║ Slower tests │ Samples │ Result │ Tolerance ║
╟──────────────────────────────┼─────────┼───────────────────┼───────────╢
║ query-string │ 10000 │ 294354.42 op/sec │ ± 1.25 % ║
║ qs │ 10000 │ 349992.31 op/sec │ ± 1.45 % ║
║ @aws-sdk/querystring-builder │ 10000 │ 380426.03 op/sec │ ± 1.69 % ║
║ http-querystring-stringify │ 10000 │ 489248.93 op/sec │ ± 1.54 % ║
║ URLSearchParams │ 10000 │ 579241.21 op/sec │ ± 1.92 % ║
║ querystringparser │ 1500 │ 667303.72 op/sec │ ± 0.77 % ║
║ querystringify │ 10000 │ 780283.61 op/sec │ ± 2.43 % ║
║ node:querystring │ 10000 │ 1779241.34 op/sec │ ± 6.49 % ║
╟──────────────────────────────┼─────────┼───────────────────┼───────────╢
║ Fastest test │ Samples │ Result │ Tolerance ║
╟──────────────────────────────┼─────────┼───────────────────┼───────────╢
║ fast-querystring │ 10000 │ 2125769.45 op/sec │ ± 3.93 % ║
╚══════════════════════════════╧═════════╧═══════════════════╧═══════════╝
```
4 changes: 4 additions & 0 deletions benchmark/parse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import native from "node:querystring";
import queryString from "query-string";
import querystringify from "querystringify";
import awsQueryStringParser from "@aws-sdk/querystring-parser";
import querystringparser from "querystringparser";

const input = "frappucino=muffin&goat=scone&pond=moose&foo=bar&foo=baz";

Expand Down Expand Up @@ -46,6 +47,9 @@ await benchmark(
"@aws-sdk/querystring-parser"() {
return awsQueryStringParser.parseQueryString(input);
},
querystringparser() {
return querystringparser.parse(input);
},
},
{ warmup: true },
);
8 changes: 8 additions & 0 deletions benchmark/stringify.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import native from "node:querystring";
import queryString from "query-string";
import querystringify from "querystringify";
import httpQuerystringStringify from "http-querystring-stringify";
import awsQueryStringBuilder from "@aws-sdk/querystring-builder";
import querystringparser from "querystringparser";

const value = {
frappucino: "muffin",
Expand Down Expand Up @@ -40,6 +42,12 @@ await benchmark(
"http-querystring-stringify"() {
return httpQuerystringStringify(value);
},
"@aws-sdk/querystring-builder"() {
return awsQueryStringBuilder.buildQueryString(value);
},
querystringparser() {
return querystringparser.stringify(value);
},
},
{ warmup: true },
);
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
"author": "Yagiz Nizipli <[email protected]>",
"license": "MIT",
"devDependencies": {
"@aws-sdk/querystring-builder": "^3.162.0",
"@aws-sdk/querystring-parser": "^3.162.0",
"@types/node": "^18.7.15",
"cronometro": "^1.1.2",
"http-querystring-stringify": "^2.1.0",
"qs": "^6.11.0",
"query-string": "^7.1.1",
"querystringify": "^2.2.0",
"querystringparser": "^0.1.1",
"rome": "0.9.1-next",
"vitest": "^0.23.1"
},
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit c2b2fbf

Please sign in to comment.