Skip to content

Commit 060af54

Browse files
CopilotDevilTea
andcommitted
feat(benchmarks): add integration with typescript-runtime-type-benchmarks for library comparison
Co-authored-by: DevilTea <16652879+DevilTea@users.noreply.github.com>
1 parent 63ee25e commit 060af54

File tree

5 files changed

+555
-0
lines changed

5 files changed

+555
-0
lines changed

benchmarks/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ pnpm bench:watch
1616

1717
- **core.bench.ts**: Core functionality benchmarks including createValchecker, object validation, arrays, unions, and complex scenarios
1818
- **steps.bench.ts**: Individual step operation benchmarks including string operations, number validation, transformations, and chaining
19+
- **comparison/**: Integration files for comparing valchecker with other libraries using typescript-runtime-type-benchmarks
1920

2021
## Reports
2122

2223
- **PERFORMANCE_REPORT.md**: Detailed performance analysis comparing baseline vs optimized implementation
2324

25+
## Comparing with Other Libraries
26+
27+
To compare valchecker with other popular validation libraries (zod, yup, joi, ajv, etc.), see:
28+
- **comparison/README.md**: Quick start guide for library comparison
29+
- **comparison/integration-guide.md**: Detailed step-by-step integration instructions
30+
- **comparison/valchecker-case.ts**: Ready-to-use case file for typescript-runtime-type-benchmarks
31+
32+
The [typescript-runtime-type-benchmarks](https://github.com/moltar/typescript-runtime-type-benchmarks) project provides standardized benchmarks across 60+ validation libraries.
33+
2434
## Benchmark Categories
2535

2636
### Core Operations

benchmarks/comparison/README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Valchecker Comparison with Other Libraries
2+
3+
This directory contains files for comparing valchecker with other validation libraries using the [typescript-runtime-type-benchmarks](https://github.com/moltar/typescript-runtime-type-benchmarks) project.
4+
5+
## Quick Start
6+
7+
### Option 1: Add Valchecker to the Benchmark Project
8+
9+
1. Clone the benchmark project:
10+
```bash
11+
git clone https://github.com/moltar/typescript-runtime-type-benchmarks.git
12+
cd typescript-runtime-type-benchmarks
13+
```
14+
15+
2. Copy the valchecker case file:
16+
```bash
17+
cp /path/to/valchecker/benchmarks/comparison/valchecker-case.ts cases/valchecker.ts
18+
```
19+
20+
3. Add valchecker as a dependency in `package.json`:
21+
```json
22+
{
23+
"dependencies": {
24+
"valchecker": "^0.0.18"
25+
}
26+
}
27+
```
28+
29+
4. Install dependencies:
30+
```bash
31+
npm install
32+
```
33+
34+
5. Run the benchmarks:
35+
```bash
36+
npm start
37+
```
38+
39+
### Option 2: Run Local Development Version
40+
41+
If you want to test the local development version of valchecker:
42+
43+
1. Build valchecker:
44+
```bash
45+
cd /path/to/valchecker
46+
pnpm build
47+
pnpm pack
48+
```
49+
50+
2. In the benchmark project, install the local package:
51+
```bash
52+
cd /path/to/typescript-runtime-type-benchmarks
53+
npm install /path/to/valchecker/valchecker-0.0.18.tgz
54+
```
55+
56+
3. Copy the case file and run benchmarks as described in Option 1.
57+
58+
## Benchmark Cases
59+
60+
The valchecker case file implements all four benchmark scenarios required by the project:
61+
62+
### 1. parseSafe
63+
Validates data and returns the parsed value. Throws on failure.
64+
65+
### 2. parseStrict
66+
Similar to parseSafe but with strict validation (same behavior for valchecker).
67+
68+
### 3. assertLoose
69+
Validates data and returns true if valid, throws on failure.
70+
71+
### 4. assertStrict
72+
Validates data strictly and returns true if valid, throws on failure.
73+
74+
## Understanding the Results
75+
76+
After running the benchmarks, you can view the results:
77+
78+
1. **Console Output**: Shows operations per second for each library
79+
2. **Generated Report**: Located in `docs/results/` with visual comparisons
80+
3. **Preview**: Available at the project's GitHub Pages
81+
82+
### Performance Metrics
83+
84+
The benchmark measures:
85+
- **ops/sec**: Operations per second (higher is better)
86+
- **margin**: Margin of error in the measurements
87+
- **Runtime**: Node.js, Bun, or Deno version used
88+
89+
## Comparing with Other Libraries
90+
91+
The benchmark project compares valchecker against popular libraries including:
92+
- zod
93+
- yup
94+
- joi
95+
- ajv
96+
- io-ts
97+
- typebox
98+
- valibot
99+
- And many more...
100+
101+
## Current Valchecker Performance
102+
103+
Based on our internal benchmarks:
104+
- Simple object validation: ~86k ops/sec
105+
- String operations: ~400k+ ops/sec
106+
- Array operations (100 objects): ~7.8k ops/sec
107+
- Complex nested structures: ~24k ops/sec
108+
109+
These numbers will be verified and compared against other libraries when integrated with the benchmark project.
110+
111+
## Notes
112+
113+
- The benchmark project uses standardized test data and scenarios
114+
- All libraries are tested under the same conditions
115+
- Results may vary based on hardware and Node.js version
116+
- The project is actively maintained and updated regularly
117+
118+
## Contributing
119+
120+
If you find issues with the valchecker case implementation or have suggestions for improvement:
121+
122+
1. Test locally with the benchmark project
123+
2. Submit issues or PRs to the valchecker repository
124+
3. Consider contributing the case upstream to typescript-runtime-type-benchmarks
125+
126+
## References
127+
128+
- [typescript-runtime-type-benchmarks](https://github.com/moltar/typescript-runtime-type-benchmarks)
129+
- [Benchmark Results](https://moltar.github.io/typescript-runtime-type-benchmarks)
130+
- [Valchecker Documentation](https://github.com/DevilTea/valchecker)

0 commit comments

Comments
 (0)