From 853d5a553555acb090852c7315f7d1227d1550b7 Mon Sep 17 00:00:00 2001 From: hpcdisrespecter <197135402+hpcdisrespecter@users.noreply.github.com> Date: Wed, 23 Apr 2025 20:38:25 -0500 Subject: [PATCH] Update utils so the benchmark is reflective of non-dead code - benchmark was likely optimized out (dead code elimination) = ! - https://github.com/evanwashere/mitata#writing-good-benchmarks --- benchmarks/utils.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/benchmarks/utils.ts b/benchmarks/utils.ts index 37c0809..ec9eb99 100644 --- a/benchmarks/utils.ts +++ b/benchmarks/utils.ts @@ -1,4 +1,4 @@ -import { bench, run, barplot, summary, compact } from 'mitata' +import { bench, run, barplot, summary, compact, do_not_optimize } from 'mitata' import { createAccelerator } from '../src' import { TypeCompiler } from '@sinclair/typebox/compiler' @@ -29,23 +29,34 @@ export const benchmark = ( barplot(() => { summary(() => { bench('JSON Stingify', () => { - return JSON.stringify(value) + do_not_optimize( () => { + const result = JSON.stringify(value) + return result + }) }) bench('Fast Json Stringify', () => { - return fastJsonStringify(value) + do_not_optimize( () => { + const result = fastJsonStringify(value) + return result + }) }) bench('JSON Accelerator', () => { - return encode(value) + do_not_optimize( () => { + const result = encode(value) + return result + }) }) const validator = TypeCompiler.Compile(model) bench('JSON Accelerator w/ validation', () => { - validator.Check(value) - - return encode(value) + do_not_optimize( () => { + validator.Check(value) + const result = encode(value) + return result + }) }) }) })