Created
May 3, 2025 17:15
-
-
Save nanto/873606402bbdae027663a3d823a0bfae to your computer and use it in GitHub Desktop.
conform-to-valibot config/fallback support benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { coerceFormValue as coerceFormValue_reuseType } from './coercion.02a0f099'; | |
import { coerceFormValue as coerceFormValue_pipeCheckInSwitch } from './coercion.efa3522b'; | |
import * as v from 'valibot'; | |
import * as Benchmark from 'benchmark'; | |
function createSchema(n: number) { | |
let keySchema = v.number(); | |
for (let i = 0; i < n; i++) { | |
keySchema = v.pipe(keySchema); | |
} | |
return v.object({ key: keySchema }); | |
} | |
const schema1 = createSchema(1); | |
const schema10 = createSchema(10); | |
const schema100 = createSchema(100); | |
const n = 100; | |
new Benchmark.Suite() | |
.add('reuseType_nested1', () => { | |
for (let i = 0; i < n; i++) { | |
const schema = coerceFormValue_reuseType(schema1); | |
} | |
}) | |
.add('reuseType_nested10', () => { | |
for (let i = 0; i < n; i++) { | |
const schema = coerceFormValue_reuseType(schema10); | |
} | |
}) | |
.add('reuseType_nested100', () => { | |
for (let i = 0; i < n; i++) { | |
const schema = coerceFormValue_reuseType(schema100); | |
} | |
}) | |
.add('pipeCheckInSwitch_nested1', () => { | |
for (let i = 0; i < n; i++) { | |
const schema = coerceFormValue_pipeCheckInSwitch(schema1); | |
} | |
}) | |
.add('pipeCheckInSwitch_nested10', () => { | |
for (let i = 0; i < n; i++) { | |
const schema = coerceFormValue_pipeCheckInSwitch(schema10); | |
} | |
}) | |
.add('pipeCheckInSwitch_nested100', () => { | |
for (let i = 0; i < n; i++) { | |
const schema = coerceFormValue_pipeCheckInSwitch(schema100); | |
} | |
}) | |
.on('cycle', function (event: any) { | |
console.log(String(event.target)); | |
}) | |
.on('complete', function () { | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
}) | |
.run({ async: true }); | |
// reuseType_nested1 x 287 ops/sec ±9.38% (57 runs sampled) | |
// reuseType_nested10 x 101 ops/sec ±6.77% (59 runs sampled) | |
// reuseType_nested100 x 13.61 ops/sec ±6.16% (40 runs sampled) | |
// pipeCheckInSwitch_nested1 x 436 ops/sec ±4.89% (63 runs sampled) | |
// pipeCheckInSwitch_nested10 x 408 ops/sec ±7.52% (51 runs sampled) | |
// pipeCheckInSwitch_nested100 x 383 ops/sec ±19.20% (55 runs sampled) | |
// Fastest is pipeCheckInSwitch_nested1,pipeCheckInSwitch_nested10,pipeCheckInSwitch_nested100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment