Skip to content

Commit

Permalink
Update main page
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed Feb 22, 2025
1 parent 92f8e75 commit e234b0e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 52 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Also, you can use **rescript-schema** as a building block for your tools. And th
- [rescript-json-schema](https://github.com/DZakh/rescript-json-schema) - Typesafe JSON schema for ReScript
- [rescript-stripe](https://github.com/enviodev/rescript-stripe) - Describe and manage Stripe billing in a declarative way with code
- Internal form library at [Carla](https://www.carla.se/)
- [tRPC](https://trpc.io/), [TanStack Form](https://tanstack.com/form), [TanStack Router](https://tanstack.com/router), [Hono](https://hono.dev/) and 15+ more using [Standard Schema](https://standardschema.dev/) spec
- [tRPC](https://trpc.io/), [TanStack Form](https://tanstack.com/form), [TanStack Router](https://tanstack.com/router), [Hono](https://hono.dev/) and 19+ more using [Standard Schema](https://standardschema.dev/) spec

## Documentation

Expand All @@ -41,6 +41,7 @@ Also, you can use **rescript-schema** as a building block for your tools. And th

## Resources

- Introduction to ReScript Schema ([Dev.to](https://dev.to/dzakh/javascript-schema-library-from-the-future-5420))
- Building and consuming REST API in ReScript with rescript-rest and Fastify ([YouTube](https://youtu.be/37FY6a-zY20?si=72zT8Gecs5vmDPlD))
- ReScript Schema V9 Changes Overview ([Dev.to](https://dev.to/dzakh/rescript-schema-v9-zod-like-library-to-the-next-level-1dn6))

Expand All @@ -60,6 +61,6 @@ At the same time **rescript-schema** is the fastest composable validation librar
| **Example size** (minified + gzipped) | 4.45 kB | 13.5 kB | 1.22 kB | 40.7 kB |
| **Parse with the same schema** | 93,491 ops/ms | 1,191 ops/ms | 3,540 ops/ms | 84,772 ops/ms |
| **Create schema & parse once** | 166 ops/ms | 93 ops/ms | 2,302 ops/ms | 13 ops/ms |
| **Eval-free** |||| |
| **Eval-free** |||| |
| **Codegen-free** (Doesn't need compiler) |||||
| **Ecosystem** | ⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ | ⭐️⭐️⭐️ | ⭐️⭐️ |
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"ts-expect": "1.3.0",
"tsimp": "2.0.12",
"typescript": "4.9.3",
"valibot": "0.42.1",
"zod": "3.24.1",
"valibot": "1.0.0-rc.1",
"zod": "3.24.2",
"arktype": "2.0.4"
},
"peerDependencies": {
Expand Down
115 changes: 77 additions & 38 deletions packages/tests/src/benchmark/comparison.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import B from "benchmark";
import { z } from "zod";
import * as V from "valibot";
import * as S from "rescript-schema/src/S.mjs";
import * as v from "valibot";
import * as S from "rescript-schema/src/S.js";
import { type } from "arktype";

const data = Object.freeze({
Expand Down Expand Up @@ -33,6 +33,33 @@ const arkType = type({
},
});

const RescriptSchemaUnion = S.union([
{ box: S.string },
S.coerce(S.string, S.number),
]);
// S.parseOrThrow("123", RescriptSchemaUnion)
// [email protected] x 82,715,204 ops/sec ±2.11% (86 runs sampled)

const ValibotUnion = v.union([
v.object({
box: v.string(),
}),
v.pipe(v.string(), v.decimal(), v.transform(Number)),
]);
// v.parse(ValibotUnion, "123")
// [email protected] x 5,507,472 ops/sec ±0.38% (98 runs sampled)

const ArkTypeUnion = type({ box: "string" }).or("string.numeric.parse");
// ArkTypeUnion("123")
// [email protected] x 4,300,118 ops/sec ±0.33% (97 runs sampled)

const ZodUnion = z.union([
z.object({ box: z.string() }),
z.string().pipe(z.coerce.number()),
]);
// ZodUnion.parse("123")
// [email protected] x 3,278,494 ops/sec ±0.55% (94 runs sampled)

const zodSchema = z.object({
number: z.number(),
negNumber: z.number(),
Expand All @@ -47,17 +74,17 @@ const zodSchema = z.object({
}),
});

const valibotSchema = V.object({
number: V.number(),
negNumber: V.number(),
maxNumber: V.number(),
string: V.string(),
longString: V.string(),
boolean: V.boolean(),
deeplyNested: V.object({
foo: V.string(),
num: V.number(),
bool: V.boolean(),
const valibotSchema = v.object({
number: v.number(),
negNumber: v.number(),
maxNumber: v.number(),
string: v.string(),
longString: v.string(),
boolean: v.boolean(),
deeplyNested: v.object({
foo: v.string(),
num: v.number(),
bool: v.boolean(),
}),
});

Expand All @@ -77,7 +104,7 @@ const schema = S.schema({
bool: S.boolean,
},
});
let parseOrThrow = S.compile(schema, "Input", "Output", "Sync", true);
const parseOrThrow = S.compile(schema, "Input", "Output", "Sync", true);

new B.Suite()
.add("rescript-schema (create)", () => {
Expand Down Expand Up @@ -117,6 +144,9 @@ new B.Suite()
});
return S.parseOrThrow(data, schema);
})
.add("rescript-schema (union)", () => {
return S.parseOrThrow("123", RescriptSchemaUnion);
})
.add("Zod (create)", () => {
return z.object({
number: z.number(),
Expand Down Expand Up @@ -151,39 +181,45 @@ new B.Suite()
});
return zodSchema.parse(data);
})
.add("Zod (union)", () => {
return ZodUnion.parse("123");
})
.add("Valibot (create)", () => {
return V.object({
number: V.number(),
negNumber: V.number(),
maxNumber: V.number(),
string: V.string(),
longString: V.string(),
boolean: V.boolean(),
deeplyNested: V.object({
foo: V.string(),
num: V.number(),
bool: V.boolean(),
return v.object({
number: v.number(),
negNumber: v.number(),
maxNumber: v.number(),
string: v.string(),
longString: v.string(),
boolean: v.boolean(),
deeplyNested: v.object({
foo: v.string(),
num: v.number(),
bool: v.boolean(),
}),
});
})
.add("Valibot (parse)", () => {
return V.parse(valibotSchema, data);
return v.parse(valibotSchema, data);
})
.add("Valibot (create + parse)", () => {
const valibotSchema = V.object({
number: V.number(),
negNumber: V.number(),
maxNumber: V.number(),
string: V.string(),
longString: V.string(),
boolean: V.boolean(),
deeplyNested: V.object({
foo: V.string(),
num: V.number(),
bool: V.boolean(),
const valibotSchema = v.object({
number: v.number(),
negNumber: v.number(),
maxNumber: v.number(),
string: v.string(),
longString: v.string(),
boolean: v.boolean(),
deeplyNested: v.object({
foo: v.string(),
num: v.number(),
bool: v.boolean(),
}),
});
return V.parse(valibotSchema, data);
return v.parse(valibotSchema, data);
})
.add("Valibot (union)", () => {
return v.parse(ValibotUnion, "123");
})
.add("ArkType (create)", () => {
return type({
Expand Down Expand Up @@ -219,6 +255,9 @@ new B.Suite()
});
return arkType(data);
})
.add("ArkType (union)", () => {
return ArkTypeUnion("123");
})
.on("cycle", (event) => {
console.log(String(event.target));
})
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

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

1 comment on commit e234b0e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: e234b0e Previous: 5d4c24f Ratio
S.schema - make 1390389 ops/sec (±0.61%) 1333035 ops/sec (±0.94%) 0.96
S.schema - make + parse 107382 ops/sec (±1.29%) 107810 ops/sec (±1.18%) 1.00
S.schema - parse 49787032 ops/sec (±1.37%) 49514611 ops/sec (±1.45%) 0.99
S.schema - parse strict 21589492 ops/sec (±1.60%) 23185793 ops/sec (±1.21%) 1.07
S.schema - make + reverse 945116 ops/sec (±0.32%) 916551 ops/sec (±0.35%) 0.97
S.schema - make + reverse convert 190356 ops/sec (±0.69%) 178335 ops/sec (±1.39%) 0.94
S.schema - reverse convert 68213474 ops/sec (±1.84%) 56582336 ops/sec (±1.79%) 0.83
S.schema - reverse convert (compiled) 139811590 ops/sec (±4.05%) 136263821 ops/sec (±4.28%) 0.97
S.schema - assert 64597085 ops/sec (±1.94%) 51172085 ops/sec (±2.32%) 0.79
S.schema - assert (compiled) 73662240 ops/sec (±2.05%) 72465443 ops/sec (±2.31%) 0.98
S.schema - assert strict 23253733 ops/sec (±1.12%) 21906524 ops/sec (±0.73%) 0.94
S.object - make 962117 ops/sec (±0.30%) 965712 ops/sec (±0.36%) 1.00
S.object - make + parse 88921 ops/sec (±0.39%) 89541 ops/sec (±0.22%) 1.01
S.object - parse 36712677 ops/sec (±1.53%) 33576635 ops/sec (±1.02%) 0.91
S.object - make + reverse 131330 ops/sec (±1.23%) 128955 ops/sec (±1.24%) 0.98
S.object - make + reverse convert 85512 ops/sec (±0.86%) 83466 ops/sec (±1.10%) 0.98
S.object - reverse convert 47757735 ops/sec (±1.40%) 46593380 ops/sec (±1.70%) 0.98
S.string - parse 69178075 ops/sec (±2.37%) 63773163 ops/sec (±2.49%) 0.92
S.string - reverse convert 72029079 ops/sec (±1.76%) 67690417 ops/sec (±2.11%) 0.94

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.