-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,471 additions
and
1,038 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,73 @@ npm run test:res | |
npm run test -- --watch | ||
``` | ||
|
||
## Make comparison | ||
|
||
https://bundlejs.com/ | ||
|
||
`rescript-schema` | ||
|
||
```ts | ||
import * as S from "github:DZakh/rescript-schema/artifacts/packages/artifacts/dist/S.mjs"; | ||
|
||
// Create login schema with email and password | ||
const loginSchema = S.object({ | ||
email: S.email(S.string), | ||
password: S.stringMinLength(S.string, 8), | ||
}); | ||
|
||
// Infer output TypeScript type of login schema | ||
type LoginData = S.Output<typeof loginSchema>; // { email: string; password: string } | ||
|
||
// Throws the S.Error(`Failed parsing at ["email"]. Reason: Invalid email address`) | ||
S.parseOrThrow(loginSchema, { email: "", password: "" }); | ||
|
||
// Returns data as { email: string; password: string } | ||
S.parseOrThrow(loginSchema, { | ||
email: "[email protected]", | ||
password: "12345678", | ||
}); | ||
``` | ||
|
||
valibot | ||
|
||
```ts | ||
import * as v from "valibot"; // 1.21 kB | ||
|
||
// Create login schema with email and password | ||
const LoginSchema = v.object({ | ||
email: v.pipe(v.string(), v.email()), | ||
password: v.pipe(v.string(), v.minLength(8)), | ||
}); | ||
|
||
// Infer output TypeScript type of login schema | ||
type LoginData = v.InferOutput<typeof LoginSchema>; // { email: string; password: string } | ||
|
||
// Throws error for `email` and `password` | ||
v.parse(LoginSchema, { email: "", password: "" }); | ||
|
||
// Returns data as { email: string; password: string } | ||
v.parse(LoginSchema, { email: "[email protected]", password: "12345678" }); | ||
``` | ||
|
||
zod | ||
|
||
```ts | ||
export * as z from "zod"; // 1.21 kB | ||
|
||
// Create login schema with email and password | ||
const LoginSchema = z.object({ | ||
email: z.string().email(), | ||
password: z.string().min(8), | ||
}); | ||
|
||
// Throws error for `email` and `password` | ||
LoginSchema.parse({ email: "", password: "" }); | ||
|
||
// Returns data as { email: string; password: string } | ||
LoginSchema.parse({ email: "[email protected]", password: "12345678" }); | ||
``` | ||
|
||
## License | ||
|
||
By contributing your code to the rescript-schema GitHub repository, you agree to license your contribution under the MIT license. |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,12 +46,12 @@ Besides the individual bundle size, the overall size of the library is also sign | |
|
||
At the same time **rescript-schema** is the fastest composable validation library in the entire JavaScript ecosystem. This is achieved because of the JIT approach when an ultra optimized validator is created using `eval`. | ||
|
||
| | rescript-schema@6.2.0 | [email protected] | Valibot@0.18.0 | | ||
| | rescript-schema@7.0.0 | [email protected] | Valibot@0.32.0 | | ||
| ----------------------------------------- | --------------------- | --------------- | -------------- | | ||
| **Total size** (minified + gzipped) | 9.67 kB | 13.4 kB | 6.73 kB | | ||
| **Example size** (minified + gzipped) | 5.53 kB | 12.8 kB | 965 B | | ||
| **Nested object parsing** | 153,787 ops/ms | 1,177 ops/ms | 3,562 ops/ms | | ||
| **Create schema + Nested object parsing** | 54 ops/ms | 110 ops/ms | 1,937 ops/ms | | ||
| **Total size** (minified + gzipped) | 9.82 kB | 14.6 kB | 9.88 kB | | ||
| **Example size** (minified + gzipped) | 4.98 kB | 12.9 kB | 1.22 B | | ||
| **Nested object parsing** | 156,244 ops/ms | 1,304 ops/ms | 3,822 ops/ms | | ||
| **Create schema + Nested object parsing** | 56 ops/ms | 112 ops/ms | 2,475 ops/ms | | ||
| **Eval-free** | ❌ | ✅ | ✅ | | ||
| **Codegen-free** (Doesn't need compiler) | ✅ | ✅ | ✅ | | ||
| **Ecosystem** | ⭐️ | ⭐️⭐️⭐️⭐️⭐️ | ⭐️⭐️ | | ||
| **Ecosystem** | ⭐️ | ⭐️⭐️⭐️⭐️⭐️ | ⭐️⭐️⭐️ | |
This file contains 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
Oops, something went wrong.
c0a38f2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
Parse string
818959423
ops/sec (±0.14%
)814044167
ops/sec (±0.15%
)0.99
Serialize string
820467046
ops/sec (±0.06%
)814166152
ops/sec (±0.12%
)0.99
Advanced object schema factory
459003
ops/sec (±0.63%
)457405
ops/sec (±0.90%
)1.00
Parse advanced object
45000813
ops/sec (±0.38%
)42985342
ops/sec (±0.72%
)0.96
Create and parse advanced object
34588
ops/sec (±1.15%
)34684
ops/sec (±1.48%
)1.00
Parse advanced strict object
22453639
ops/sec (±0.39%
)21540357
ops/sec (±0.57%
)0.96
Serialize advanced object
803572476
ops/sec (±0.09%
)800158749
ops/sec (±0.09%
)1.00
This comment was automatically generated by workflow using github-action-benchmark.