Skip to content

Commit

Permalink
Merge pull request #287 from samchon/features/assert
Browse files Browse the repository at this point in the history
Benchmark #281 with my computers
  • Loading branch information
samchon authored Oct 30, 2022
2 parents fb31b84 + 3ba6158 commit c7e7341
Show file tree
Hide file tree
Showing 6 changed files with 2,552 additions and 361 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ TSON.application<[T, U, V], "ajv">(); // JSON schema application generator
- Guarded by type validation: `TSON.assertStringify<T>(input)`
- Only one library which can stringify union type

![Is Function Benchmark](https://user-images.githubusercontent.com/13158709/197366076-1d5592e7-b717-4ea3-b9d7-949e7fa4fc76.png)
![Is Function Benchmark](https://user-images.githubusercontent.com/13158709/198886897-13fe8c27-3f66-41e6-b7ed-b2cb40381937.png)

![Assert Function Benchmark](https://user-images.githubusercontent.com/13158709/197366105-2b784668-70dd-44bf-b73d-2e601e54c48f.png)
![Assert Function Benchmark](https://user-images.githubusercontent.com/13158709/198886957-92571095-e2cb-4a84-8706-c121a28d8f48.png)

> Measured on AMD R9 5900HX and Intel i5-1135g7
> Measured on AMD R7 5800H


Expand Down Expand Up @@ -258,9 +258,9 @@ As you can see from the above table, `ajv` and `typescript-is` are fallen in the

The extreme different is shown in the "ultimate union" type, when validating [JSON schema](https://github.com/samchon/typescript-json/blob/master/src/schemas/IJsonSchema.ts).

![Super-fast runtime validator](https://user-images.githubusercontent.com/13158709/197246323-d4b319bc-38ee-492a-97b1-62b1981c082b.png)
![Super-fast runtime validator](https://user-images.githubusercontent.com/13158709/198886993-e309c0ae-6b9a-4d6b-adf6-ba3caa688ad0.png)

> Measured on AMD-5800H
> Measured on AMD R9 5900HX
### Fastest JSON String Converter
```typescript
Expand All @@ -281,9 +281,9 @@ If you want to validate the input type at the same time, you can choose `TSON.is

Comparing performance, `typescript-json` is about 5x times faster than the native `JSON.stringify()` function.

![JSON conversion speed on each CPU](https://user-images.githubusercontent.com/13158709/197731958-f20157b2-2e31-4e24-a27f-3ae9a8e565bb.png)
![JSON conversion speed on each CPU](https://user-images.githubusercontent.com/13158709/198887389-df94f6e9-6d25-4943-8636-84b5c23c1369.png)

> Measured on Intel AMD-5800H
> Measured by Intel i5-1135g7, Surface Pro 8
### JSON Schema Generation
```typescript
Expand Down
16 changes: 0 additions & 16 deletions benchmark/features/benchmark_is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { ArrayRecursiveUnionExplicit } from "../../test/structures/ArrayRecursiv
import { ArrayRecursiveUnionImplicit } from "../../test/structures/ArrayRecursiveUnionImplicit";
import { ObjectHierarchical } from "../../test/structures/ObjectHierarchical";
import { ObjectRecursive } from "../../test/structures/ObjectRecursive";
import { ObjectSimple } from "../../test/structures/ObjectSimple";
import { ObjectUnionExplicit } from "../../test/structures/ObjectUnionExplicit";
import { ObjectUnionImplicit } from "../../test/structures/ObjectUnionImplicit";
import { UltimateUnion } from "../../test/structures/UltimateUnion";
Expand All @@ -26,7 +25,6 @@ import { AjvArrayRecursiveUnionExplicit } from "../structures/ajv/AjvArrayRecurs
import { AjvArrayRecursiveUnionImplicit } from "../structures/ajv/AjvArrayRecursiveUnionImplicit";
import { AjvObjectHierarchical } from "../structures/ajv/AjvObjectHierarchical";
import { AjvObjectRecursive } from "../structures/ajv/AjvObjectRecursive";
import { AjvObjectSimple } from "../structures/ajv/AjvObjectSimple";
import { AjvObjectUnionExplicit } from "../structures/ajv/AjvObjectUnionExplicit";
import { AjvObjectUnionImplicit } from "../structures/ajv/AjvObjectUnionImplicit";
import { AjvUltimateUnion } from "../structures/ajv/AjvUltimateUnion";
Expand All @@ -36,7 +34,6 @@ import { CvArrayRecursiveUnionExplicit } from "../structures/class-validator/CvA
import { CvArrayRecursiveUnionImplicit } from "../structures/class-validator/CvArrayRecursiveUnionImplicit";
import { CvObjectHierarchical } from "../structures/class-validator/CvObjectHierarchical";
import { CvObjectRecursive } from "../structures/class-validator/CvObjectRecursive";
import { CvObjectSimple } from "../structures/class-validator/CvObjectSimple";
import { CvObjectUnionExplicit } from "../structures/class-validator/CvObjectUnionExplicit";
import { CvObjectUnionImplicit } from "../structures/class-validator/CvObjectUnionImplicit";
// IO-TS TYPES
Expand Down Expand Up @@ -109,19 +106,6 @@ const prepare = IsBenchmarker.prepare([
DO BENCHMARK
----------------------------------------------------------- */
const is = () => [
prepare(
"object (simple)",
() => ObjectSimple.generate(),
{
"typescript-json": TSON.createIs<ObjectSimple>(),
"io-ts": isIoTs(IoTsObjectSimple),
"class-validator": isClassValidator(CvObjectSimple),
zod: isZod(ZodObjectSimple),
typebox: isTypeBox(TypeBoxObjectSimple),
ajv: isAjv(AjvObjectSimple),
},
ObjectSimple.SPOILERS,
),
prepare(
"object (hierarchical)",
() => ObjectHierarchical.generate(),
Expand Down
Loading

0 comments on commit c7e7341

Please sign in to comment.