Skip to content

Commit

Permalink
chore: add zod-to-json-schema to benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Aug 7, 2024
1 parent a6c66de commit 4a27c67
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
14 changes: 13 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ file: tschema/scripts/bench.ts
runtime: deno 1.45.5 (aarch64-apple-darwin)
# Builders
tschema 5,273,942.5 iter/sec 189.61 ns/iter
sinclair/typebox 130,548.3 iter/sec 7.66 µs/iter
tschema 5,328,603.3 iter/sec 187.67 ns/iter
sinclair/typebox 130,480.2 iter/sec 7.66 µs/iter
zod-to-json-schema 46,928.5 iter/sec 21.31 µs/iter
# Summary
tschema
40.4x faster than sinclair/typebox
40.84x faster than sinclair/typebox
113.55x faster than zod-to-json-schema
```

## License
Expand Down
27 changes: 27 additions & 0 deletions scripts/bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as t from '../mod.ts';
import { Type } from 'npm:@sinclair/typebox';
import { zodToJsonSchema } from 'npm:zod-to-json-schema';
import { z } from 'npm:zod';

Deno.bench('tschema', { group: 'builder' }, () => {
let _ = t.object({
Expand Down Expand Up @@ -69,3 +71,28 @@ Deno.bench('sinclair/typebox', { group: 'builder' }, () => {
}),
});
});

Deno.bench('zod-to-json-schema', { group: 'builder' }, () => {
let zod = z.object({
uid: z.number().int(),
name: z.string({
description: 'full name',
}),
isActive: z.boolean(),
avatar: z.optional(
z.string().url(),
),
achievements: z.tuple([
z.number().min(0), // points
z.enum(['novice', 'pro', 'expert', 'master']),
]),
interests: z.array(
z.string().min(4).max(36),
),
last_updated: z.number({
description: 'unix seconds',
}).int().min(0),
});

let _ = zodToJsonSchema(zod);
});

0 comments on commit 4a27c67

Please sign in to comment.