Skip to content

Commit c59dd8f

Browse files
cesco69Simone Nigro
andauthored
feat: enhance benchmarking output structure (#816)
* feat: enhance benchmarking output structure Refactor benchmarking output to categorize results by scenario and library, improving readability and organization of performance metrics. Signed-off-by: francesco <francesco.bagnoli.69@gmail.com> * Fix string matching for scenario identification Signed-off-by: francesco <francesco.bagnoli.69@gmail.com> * Change condition to check for 'creation' in name Signed-off-by: francesco <francesco.bagnoli.69@gmail.com> * Fix formatting in error logging for benchmark script Signed-off-by: francesco <francesco.bagnoli.69@gmail.com> * Refactor benchmark suite to improve naming consistency Signed-off-by: francesco <francesco.bagnoli.69@gmail.com> --------- Signed-off-by: francesco <francesco.bagnoli.69@gmail.com> Co-authored-by: Simone Nigro <simone.nigro@acca.it>
1 parent 07c4a21 commit c59dd8f

1 file changed

Lines changed: 60 additions & 44 deletions

File tree

benchmark/bench-cmp-lib.js

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -169,155 +169,171 @@ for (let i = STR_LEN; i < LARGE_ARRAY_SIZE; ++i) {
169169
}
170170
}
171171

172-
Number(str)
173-
174172
for (let i = 0; i < MULTI_ARRAY_LENGTH; i++) {
175173
multiArray[i] = obj
176174
}
177175

178-
suite.add('FJS creation', function () {
176+
suite.add('fast-json-stringify: creation', function () {
179177
FJS(schema)
180178
})
181-
suite.add('CJS creation', function () {
179+
suite.add('compile-json-stringify: creation', function () {
182180
CJS(schemaCJS)
183181
})
184-
suite.add('AJV Serialize creation', function () {
182+
suite.add('AJV: creation', function () {
185183
ajv.compileSerializer(schemaAJVJTD)
186184
})
187-
suite.add('json-accelerator creation', function () {
185+
suite.add('json-accelerator: creation', function () {
188186
createAccelerator(schema)
189187
})
190188

191-
suite.add('JSON.stringify array', function () {
189+
suite.add('JSON.stringify: array', function () {
192190
JSON.stringify(multiArray)
193191
})
194192

195-
suite.add('fast-json-stringify array default', function () {
193+
suite.add('fast-json-stringify [default]: array', function () {
196194
stringifyArrayDefault(multiArray)
197195
})
198196

199-
suite.add('json-accelerator array', function () {
197+
suite.add('json-accelerator: array', function () {
200198
accelArray(multiArray)
201199
})
202200

203-
suite.add('fast-json-stringify array json-stringify', function () {
201+
suite.add('fast-json-stringify [json-stringify]: array', function () {
204202
stringifyArrayJSONStringify(multiArray)
205203
})
206204

207-
suite.add('compile-json-stringify array', function () {
205+
suite.add('compile-json-stringify: array', function () {
208206
CJSStringifyArray(multiArray)
209207
})
210208

211-
suite.add('AJV Serialize array', function () {
209+
suite.add('AJV: array', function () {
212210
ajvSerializeArray(multiArray)
213211
})
214212

215-
suite.add('JSON.stringify large array', function () {
213+
suite.add('JSON.stringify: large array', function () {
216214
JSON.stringify(largeArray)
217215
})
218216

219-
suite.add('fast-json-stringify large array default', function () {
217+
suite.add('fast-json-stringify [default]: large array', function () {
220218
stringifyArrayDefault(largeArray)
221219
})
222220

223-
suite.add('fast-json-stringify large array json-stringify', function () {
221+
suite.add('fast-json-stringify [json-stringify]: large array', function () {
224222
stringifyArrayJSONStringify(largeArray)
225223
})
226224

227-
suite.add('compile-json-stringify large array', function () {
225+
suite.add('compile-json-stringify: large array', function () {
228226
CJSStringifyArray(largeArray)
229227
})
230228

231-
suite.add('AJV Serialize large array', function () {
229+
suite.add('AJV: large array', function () {
232230
ajvSerializeArray(largeArray)
233231
})
234232

235-
suite.add('JSON.stringify long string', function () {
233+
suite.add('JSON.stringify: long string', function () {
236234
JSON.stringify(str)
237235
})
238236

239-
suite.add('fast-json-stringify long string', function () {
237+
suite.add('fast-json-stringify: long string', function () {
240238
stringifyString(str)
241239
})
242240

243-
suite.add('json-accelerator long string', function () {
241+
suite.add('json-accelerator: long string', function () {
244242
stringifyString(str)
245243
})
246244

247-
suite.add('compile-json-stringify long string', function () {
245+
suite.add('compile-json-stringify: long string', function () {
248246
CJSStringifyString(str)
249247
})
250248

251-
suite.add('AJV Serialize long string', function () {
249+
suite.add('AJV: long string', function () {
252250
ajvSerializeString(str)
253251
})
254252

255-
suite.add('JSON.stringify short string', function () {
253+
suite.add('JSON.stringify: short string', function () {
256254
JSON.stringify('hello world')
257255
})
258256

259-
suite.add('fast-json-stringify short string', function () {
257+
suite.add('fast-json-stringify: short string', function () {
260258
stringifyString('hello world')
261259
})
262260

263-
suite.add('json-accelerator short string', function () {
261+
suite.add('json-accelerator: short string', function () {
264262
accelString('hello world')
265263
})
266264

267-
suite.add('compile-json-stringify short string', function () {
265+
suite.add('compile-json-stringify: short string', function () {
268266
CJSStringifyString('hello world')
269267
})
270268

271-
suite.add('AJV Serialize short string', function () {
269+
suite.add('AJV: short string', function () {
272270
ajvSerializeString('hello world')
273271
})
274272

275-
suite.add('JSON.stringify obj', function () {
273+
suite.add('JSON.stringify: obj', function () {
276274
JSON.stringify(obj)
277275
})
278276

279-
suite.add('fast-json-stringify obj', function () {
277+
suite.add('fast-json-stringify: obj', function () {
280278
stringify(obj)
281279
})
282280

283-
suite.add('json-accelerator obj', function () {
281+
suite.add('json-accelerator: obj', function () {
284282
accelStringify(obj)
285283
})
286284

287-
suite.add('compile-json-stringify obj', function () {
285+
suite.add('compile-json-stringify: obj', function () {
288286
CJSStringify(obj)
289287
})
290288

291-
suite.add('AJV Serialize obj', function () {
289+
suite.add('AJV: obj', function () {
292290
ajvSerialize(obj)
293291
})
294292

295-
suite.add('JSON stringify date', function () {
293+
suite.add('JSON.stringify: date', function () {
296294
JSON.stringify(date)
297295
})
298296

299-
suite.add('fast-json-stringify date format', function () {
297+
suite.add('fast-json-stringify: date', function () {
300298
stringifyDate(date)
301299
})
302300

303-
suite.add('json-accelerate date format', function () {
301+
suite.add('json-accelerate: date', function () {
304302
accelDate(date)
305303
})
306304

307-
suite.add('compile-json-stringify date format', function () {
305+
suite.add('compile-json-stringify: date', function () {
308306
CJSStringifyDate(date)
309307
})
310308

311309
suite.run().then(() => {
312-
for (const task of suite.tasks) {
313-
const hz = task.result.throughput.mean // ops/sec
314-
const rme = task.result.latency.rme // relative margin of error (%)
315-
const samples = task.result.latency.df + 1 // degrees of freedom + 1 = sample count
310+
const results = suite.tasks.map(task => ({
311+
name: task.name,
312+
hz: task.result.throughput.mean,
313+
rme: task.result.latency.rme,
314+
samples: task.result.latency.df + 1
315+
}))
316+
317+
const scenarios = {}
318+
for (const result of results) {
319+
const [library, scenario] = result.name.split(':').map(s => s.trim())
320+
321+
if (!scenarios[scenario]) scenarios[scenario] = []
322+
scenarios[scenario].push({ ...result, library })
323+
}
316324

317-
const formattedHz = hz.toLocaleString('en-US', { maximumFractionDigits: 0 })
318-
const formattedRme = rme.toFixed(2)
325+
for (const [scenario, tasks] of Object.entries(scenarios)) {
326+
console.log(`\n--- ${scenario} ---`)
327+
const sorted = tasks.sort((a, b) => b.hz - a.hz)
328+
const winner = sorted[0]
319329

320-
const output = `${task.name} x ${formattedHz} ops/sec ±${formattedRme}% (${samples} runs sampled)`
321-
console.log(output)
330+
for (const task of sorted) {
331+
const formattedHz = task.hz.toLocaleString('en-US', { maximumFractionDigits: 0 })
332+
const formattedRme = task.rme.toFixed(2)
333+
const isWinner = task === winner
334+
const prefix = isWinner ? '🏆 ' : ' '
335+
336+
console.log(`${prefix}${task.library.padEnd(40)} x ${formattedHz.padStart(15)} ops/sec ±${formattedRme}% (${task.samples} runs sampled)`)
337+
}
322338
}
323339
}).catch(err => console.error(`Error: ${err.message}`))

0 commit comments

Comments
 (0)