Skip to content

Commit 0cb124f

Browse files
committed
feat(benchmark): enhance performance benchmarking workflow and update query retrieval logic
1 parent 9e54f20 commit 0cb124f

File tree

5 files changed

+233
-50
lines changed

5 files changed

+233
-50
lines changed

.github/workflows/benchmark.yml

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,65 @@
11
name: Performance Benchmark
22

33
on:
4-
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
88

99
jobs:
10-
benchmark:
11-
name: Run Performance Benchmarks
12-
runs-on: ubuntu-latest
13-
14-
strategy:
15-
matrix:
16-
node-version: [0.8, 0.9, 0.10, 0.11, 0.12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
17-
fail-fast: false
18-
19-
steps:
20-
- name: Checkout code
21-
uses: actions/checkout@v4
22-
with:
23-
fetch-depth: 0
24-
25-
- name: Install dependencies
26-
uses: ljharb/actions/node/install@main
27-
with:
28-
node-version: ${{ matrix.node-version }}
29-
30-
- name: Install benchmark dependencies
31-
run: cd benchmark && npm install
32-
33-
# For PRs: Run benchmarks and compare against committed baseline
34-
- name: Run benchmarks and compare against baseline
35-
if: ${{ github.event_name == 'pull_request' }}
36-
run: |
37-
echo "==== Running benchmarks and comparing against baseline ===="
38-
# Run benchmarks using the compare script that uses the committed baseline
39-
npm run benchmark:compare
40-
41-
# Print the Node.js version for debugging
42-
echo "Benchmark completed on Node.js version: $(node --version)"
43-
44-
# For pushes to main: Run benchmarks against the committed baseline
45-
- name: Run benchmarks on main branch
46-
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
47-
run: |
48-
# Run benchmarks against the committed baseline
49-
npm run benchmark:compare
50-
51-
# Print the Node.js version for debugging
52-
echo "Benchmark completed on Node.js version: $(node --version)"
10+
matrix:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
latest: ${{ steps.set-matrix.outputs.requireds }}
14+
nonlatest: ${{ steps.set-matrix.outputs.optionals }}
15+
steps:
16+
- uses: ljharb/actions/node/matrix@main
17+
id: set-matrix
18+
with:
19+
versionsAsRoot: true
20+
type: majors
21+
preset: '>= 0.8'
22+
23+
benchmark:
24+
needs: [matrix]
25+
name: Run Performance Benchmarks
26+
runs-on: ubuntu-latest
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Install dependencies
39+
uses: ljharb/actions/node/install@main
40+
with:
41+
node-version: ${{ matrix.node-version }}
42+
43+
- name: Install benchmark dependencies
44+
run: cd benchmark && npm install
45+
46+
# For PRs: Run benchmarks and compare against committed baseline
47+
- name: Run benchmarks and compare against baseline
48+
if: ${{ github.event_name == 'pull_request' }}
49+
run: |
50+
echo "==== Running benchmarks and comparing against baseline ===="
51+
# Run benchmarks using the compare script that uses the committed baseline
52+
npm run benchmark:compare
53+
54+
# Print the Node.js version for debugging
55+
echo "Benchmark completed on Node.js version: $(node --version)"
56+
57+
# For pushes to main: Run benchmarks against the committed baseline
58+
- name: Run benchmarks on main branch
59+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
60+
run: |
61+
# Run benchmarks against the committed baseline
62+
npm run benchmark:compare
63+
64+
# Print the Node.js version for debugging
65+
echo "Benchmark completed on Node.js version: $(node --version)"
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
{
2+
"timestamp": "2025-06-25T09:40:44.605Z",
3+
"nodeVersion": "v20.10.0",
4+
"platform": "linux-x64",
5+
"results": [
6+
{
7+
"name": "Parse simple tiny query",
8+
"hz": 700446.7570730115,
9+
"rme": 0.47019748081668106,
10+
"mean": 0.0000014276602609722189,
11+
"sample": 96,
12+
"fastest": true,
13+
"slowest": false
14+
},
15+
{
16+
"name": "Parse simple small query",
17+
"hz": 336434.24503359693,
18+
"rme": 0.34792446081693845,
19+
"mean": 0.0000029723490243989227,
20+
"sample": 96,
21+
"fastest": false,
22+
"slowest": false
23+
},
24+
{
25+
"name": "Parse simple medium query",
26+
"hz": 77657.33933201671,
27+
"rme": 1.2290131874191983,
28+
"mean": 0.000012877082946720507,
29+
"sample": 93,
30+
"fastest": false,
31+
"slowest": false
32+
},
33+
{
34+
"name": "Parse simple large query",
35+
"hz": 15483.077919643303,
36+
"rme": 1.0394997175367129,
37+
"mean": 0.00006458664131188703,
38+
"sample": 94,
39+
"fastest": false,
40+
"slowest": true
41+
},
42+
{
43+
"name": "Parse shallow nested",
44+
"hz": 325546.5696069361,
45+
"rme": 0.8400644965677532,
46+
"mean": 0.0000030717571412513945,
47+
"sample": 94,
48+
"fastest": false,
49+
"slowest": false
50+
},
51+
{
52+
"name": "Parse medium nested",
53+
"hz": 250218.25448331604,
54+
"rme": 0.6073196646741952,
55+
"mean": 0.000003996510974248994,
56+
"sample": 91,
57+
"fastest": false,
58+
"slowest": false
59+
},
60+
{
61+
"name": "Parse deep nested",
62+
"hz": 136491.5894729609,
63+
"rme": 0.7634530804662536,
64+
"mean": 0.000007326458750032366,
65+
"sample": 91,
66+
"fastest": false,
67+
"slowest": false
68+
},
69+
{
70+
"name": "Parse simple array",
71+
"hz": 360522.3563161753,
72+
"rme": 1.0817812119469699,
73+
"mean": 0.0000027737530904269574,
74+
"sample": 90,
75+
"fastest": false,
76+
"slowest": false
77+
},
78+
{
79+
"name": "Parse indexed array",
80+
"hz": 213839.7258363581,
81+
"rme": 0.8390830972300877,
82+
"mean": 0.000004676399560880727,
83+
"sample": 96,
84+
"fastest": false,
85+
"slowest": false
86+
},
87+
{
88+
"name": "Parse mixed array/object",
89+
"hz": 152010.30442415894,
90+
"rme": 0.681147003731818,
91+
"mean": 0.00000657850139691629,
92+
"sample": 94,
93+
"fastest": false,
94+
"slowest": false
95+
},
96+
{
97+
"name": "Parse e-commerce query",
98+
"hz": 106558.1082903929,
99+
"rme": 0.6626615850329857,
100+
"mean": 0.000009384550983908169,
101+
"sample": 96,
102+
"fastest": false,
103+
"slowest": false
104+
},
105+
{
106+
"name": "Parse form data",
107+
"hz": 122768.06955488255,
108+
"rme": 0.8265255924563661,
109+
"mean": 0.000008145440452274583,
110+
"sample": 96,
111+
"fastest": false,
112+
"slowest": false
113+
},
114+
{
115+
"name": "Parse API query",
116+
"hz": 97874.83017688894,
117+
"rme": 0.8274896683987512,
118+
"mean": 0.000010217131393154936,
119+
"sample": 96,
120+
"fastest": false,
121+
"slowest": false
122+
},
123+
{
124+
"name": "Parse empty values",
125+
"hz": 491059.0612562051,
126+
"rme": 0.48966978256552796,
127+
"mean": 0.0000020364149221518186,
128+
"sample": 96,
129+
"fastest": false,
130+
"slowest": false
131+
},
132+
{
133+
"name": "Parse special characters",
134+
"hz": 645302.8387411962,
135+
"rme": 0.3827488929620588,
136+
"mean": 0.0000015496600045193012,
137+
"sample": 98,
138+
"fastest": false,
139+
"slowest": false
140+
},
141+
{
142+
"name": "Parse with allowDots",
143+
"hz": 367165.535073916,
144+
"rme": 0.5874425201490753,
145+
"mean": 0.0000027235671774004737,
146+
"sample": 97,
147+
"fastest": false,
148+
"slowest": false
149+
},
150+
{
151+
"name": "Parse with comma arrays",
152+
"hz": 618980.4478028473,
153+
"rme": 1.0456187026653216,
154+
"mean": 0.0000016155599155831688,
155+
"sample": 93,
156+
"fastest": false,
157+
"slowest": false
158+
},
159+
{
160+
"name": "Parse with depth limit",
161+
"hz": 146680.99110890136,
162+
"rme": 0.6964193009900447,
163+
"mean": 0.000006817515974224384,
164+
"sample": 95,
165+
"fastest": false,
166+
"slowest": false
167+
}
168+
]
169+
}

benchmark/fixtures.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ module.exports = {
237237
stress: stressTestQueries
238238
};
239239

240-
return queries[type]?.[size] || simpleQueries.medium;
240+
return (queries[type] && queries[type][size]) ? queries[type][size] : simpleQueries.medium;
241241
},
242242

243243
generateObject: (type) => {

benchmark/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "Benchmarking suite for qs library",
55
"dependencies": {
66
"benchmark": "^2.1.4",
7-
"table": "^6.8.1",
87
"colors": "=1.4.0"
98
}
109
}

benchmark/runner.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
'use strict';
22

33
var Benchmark = require('benchmark');
4-
var table = require('table').table;
54
var colors = require('colors');
65
var fs = require('fs');
76
var path = require('path');
87

98
// Load polyfills for older Node.js versions
109
require('./polyfills');
1110

11+
function table(data) {
12+
return data.map(row => row.join('\t')).join('\n');
13+
};
1214
function BenchmarkRunner(options) {
1315
options = options || {};
1416

0 commit comments

Comments
 (0)