Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions benchmarks/utils.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -29,23 +29,34 @@ export const benchmark = <T extends TAnySchema>(
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
})
})
})
})
Expand Down