diff --git a/benchmarks/array.ts b/benchmarks/array.ts index a0bb629..3cfc101 100644 --- a/benchmarks/array.ts +++ b/benchmarks/array.ts @@ -1,8 +1,9 @@ // @ts-ignore import Benchmark from 'benchmark' import { z } from 'zod' -import yup from 'yup' +import * as yup from 'yup' import vine from '../index.js' +import * as valibot from 'valibot' function getData() { return { @@ -54,6 +55,15 @@ const vineSchema = vine.compile( }) ) +const valibotSchema = valibot.object({ + contacts: valibot.array( + valibot.object({ + type: valibot.string(), + value: valibot.string(), + }) + ), +}) + console.log('======================') console.log('Benchmarking arrays') console.log('======================') @@ -78,6 +88,12 @@ suite yupSchema.validate(getData()).then(() => deferred.resolve()) }, }) + .add('Valibot', { + defer: true, + fn: function (deferred: any) { + valibot.parseAsync(valibotSchema, getData()).then(() => deferred.resolve()) + }, + }) .on('cycle', function (event: any) { console.log(String(event.target)) }) diff --git a/benchmarks/flat_object.ts b/benchmarks/flat_object.ts index e6eccfb..d623abc 100644 --- a/benchmarks/flat_object.ts +++ b/benchmarks/flat_object.ts @@ -1,8 +1,9 @@ // @ts-ignore import Benchmark from 'benchmark' import { z } from 'zod' -import yup from 'yup' +import * as yup from 'yup' import vine from '../index.js' +import * as valibot from 'valibot' function getData() { return { @@ -30,6 +31,11 @@ const vineSchema = vine.compile( }) ) +const valibotSchema = valibot.object({ + username: valibot.string(), + password: valibot.string(), +}) + console.log('===============================') console.log('Benchmarking with flat object') console.log('===============================') @@ -54,6 +60,12 @@ suite yupSchema.validate(getData()).then(() => deferred.resolve()) }, }) + .add('Valibot', { + defer: true, + fn: function (deferred: any) { + valibot.parseAsync(valibotSchema, getData()).then(() => deferred.resolve()) + }, + }) .on('cycle', function (event: any) { console.log(String(event.target)) }) diff --git a/benchmarks/nested_object.ts b/benchmarks/nested_object.ts index a0b8df1..1094dae 100644 --- a/benchmarks/nested_object.ts +++ b/benchmarks/nested_object.ts @@ -1,8 +1,9 @@ // @ts-ignore import Benchmark from 'benchmark' import { z } from 'zod' -import yup from 'yup' +import * as yup from 'yup' import vine from '../index.js' +import * as valibot from 'valibot' function getData() { return { @@ -48,6 +49,15 @@ const vineSchema = vine.compile( }) ) +const valibotSchame = valibot.object({ + username: valibot.string(), + password: valibot.string(), + contact: valibot.object({ + name: valibot.string(), + address: valibot.optional(valibot.string()), + }), +}) + console.log('=================================') console.log('Benchmarking with nested object') console.log('=================================') @@ -72,6 +82,12 @@ suite yupSchema.validate(getData()).then(() => deferred.resolve()) }, }) + .add('Valibot', { + defer: true, + fn: function (deferred: any) { + valibot.parseAsync(valibotSchame, getData()).then(() => deferred.resolve()) + }, + }) .on('cycle', function (event: any) { console.log(String(event.target)) }) diff --git a/benchmarks/union.ts b/benchmarks/union.ts index 42d5dcf..2de5938 100644 --- a/benchmarks/union.ts +++ b/benchmarks/union.ts @@ -2,6 +2,7 @@ import Benchmark from 'benchmark' import { z } from 'zod' import vine from '../index.js' +import * as valibot from 'valibot' function getData() { return { @@ -46,6 +47,19 @@ const vineSchema = vine.compile( }) ) +const valibotSchema = valibot.object({ + contact: valibot.union([ + valibot.object({ + type: valibot.literal('email'), + email: valibot.string(), + }), + valibot.object({ + type: valibot.literal('phone'), + mobile_number: valibot.string(), + }), + ]), +}) + console.log('=======================') console.log('Benchmarking unions') console.log('=======================') @@ -64,6 +78,12 @@ suite zodSchema.parseAsync(getData()).then(() => deferred.resolve()) }, }) + .add('Valibot', { + defer: true, + fn: function (deferred: any) { + valibot.parseAsync(valibotSchema, getData()).then(() => deferred.resolve()) + }, + }) .on('cycle', function (event: any) { console.log(String(event.target)) }) diff --git a/package.json b/package.json index 595807b..7937966 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "ts-node": "^10.9.2", "tsup": "^8.0.1", "typescript": "^5.3.3", + "valibot": "^0.28.1", "yup": "^1.3.3", "zod": "^3.22.4" },