Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Valibot to benchmarks #33

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion benchmarks/array.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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('======================')
Expand All @@ -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))
})
Expand Down
14 changes: 13 additions & 1 deletion benchmarks/flat_object.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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('===============================')
Expand All @@ -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))
})
Expand Down
18 changes: 17 additions & 1 deletion benchmarks/nested_object.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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('=================================')
Expand All @@ -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))
})
Expand Down
20 changes: 20 additions & 0 deletions benchmarks/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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('=======================')
Expand All @@ -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))
})
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Loading