Files
typebox/docs/benchmark.md

10 KiB

Home | Installation | Usage | Types | Values | Syntax | TypeRegistry | TypeCheck

Benchmark

This project maintains a set of benchmarks that measure Ajv, Value and TypeCompiler compilation and validation performance. These benchmarks can be run locally by cloning this repository and running npm run benchmark. The results below show for Ajv version 8.12.0 running on Node 20.10.0.

For additional comparative benchmarks, please refer to typescript-runtime-type-benchmarks.

Compile

This benchmark measures compilation performance for varying types.

┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
 (index)                     Iterations  Ajv           TypeCompiler  Performance  
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
 Literal_String              1000        '    211 ms'  '      8 ms'  '   26.38 x' 
 Literal_Number              1000        '    185 ms'  '      5 ms'  '   37.00 x' 
 Literal_Boolean             1000        '    195 ms'  '      4 ms'  '   48.75 x' 
 Primitive_Number            1000        '    149 ms'  '      7 ms'  '   21.29 x' 
 Primitive_String            1000        '    135 ms'  '      5 ms'  '   27.00 x' 
 Primitive_String_Pattern    1000        '    193 ms'  '     10 ms'  '   19.30 x' 
 Primitive_Boolean           1000        '    152 ms'  '      4 ms'  '   38.00 x' 
 Primitive_Null              1000        '    147 ms'  '      4 ms'  '   36.75 x' 
 Object_Unconstrained        1000        '   1065 ms'  '     26 ms'  '   40.96 x' 
 Object_Constrained          1000        '   1183 ms'  '     26 ms'  '   45.50 x' 
 Object_Vector3              1000        '    407 ms'  '      9 ms'  '   45.22 x' 
 Object_Box3D                1000        '   1777 ms'  '     24 ms'  '   74.04 x' 
 Tuple_Primitive             1000        '    485 ms'  '     11 ms'  '   44.09 x' 
 Tuple_Object                1000        '   1344 ms'  '     17 ms'  '   79.06 x' 
 Composite_Intersect         1000        '    606 ms'  '     14 ms'  '   43.29 x' 
 Composite_Union             1000        '    522 ms'  '     17 ms'  '   30.71 x' 
 Math_Vector4                1000        '    851 ms'  '      9 ms'  '   94.56 x' 
 Math_Matrix4                1000        '    406 ms'  '     10 ms'  '   40.60 x' 
 Array_Primitive_Number      1000        '    367 ms'  '      6 ms'  '   61.17 x' 
 Array_Primitive_String      1000        '    339 ms'  '      7 ms'  '   48.43 x' 
 Array_Primitive_Boolean     1000        '    325 ms'  '      5 ms'  '   65.00 x' 
 Array_Object_Unconstrained  1000        '   1863 ms'  '     21 ms'  '   88.71 x' 
 Array_Object_Constrained    1000        '   1535 ms'  '     18 ms'  '   85.28 x' 
 Array_Tuple_Primitive       1000        '    829 ms'  '     14 ms'  '   59.21 x' 
 Array_Tuple_Object          1000        '   1674 ms'  '     14 ms'  '  119.57 x' 
 Array_Composite_Intersect   1000        '    789 ms'  '     13 ms'  '   60.69 x' 
 Array_Composite_Union       1000        '    822 ms'  '     15 ms'  '   54.80 x' 
 Array_Math_Vector4          1000        '   1129 ms'  '     14 ms'  '   80.64 x' 
 Array_Math_Matrix4          1000        '    673 ms'  '      9 ms'  '   74.78 x' 
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┘

Validate

This benchmark measures validation performance for varying types.

┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
 (index)                     Iterations  ValueCheck    Ajv           TypeCompiler  Performance  
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
 Literal_String              1000000     '     17 ms'  '      5 ms'  '      5 ms'  '    1.00 x' 
 Literal_Number              1000000     '     14 ms'  '     18 ms'  '      9 ms'  '    2.00 x' 
 Literal_Boolean             1000000     '     14 ms'  '     20 ms'  '      9 ms'  '    2.22 x' 
 Primitive_Number            1000000     '     17 ms'  '     19 ms'  '      9 ms'  '    2.11 x' 
 Primitive_String            1000000     '     17 ms'  '     18 ms'  '     10 ms'  '    1.80 x' 
 Primitive_String_Pattern    1000000     '    172 ms'  '     46 ms'  '     41 ms'  '    1.12 x' 
 Primitive_Boolean           1000000     '     14 ms'  '     19 ms'  '     10 ms'  '    1.90 x' 
 Primitive_Null              1000000     '     16 ms'  '     19 ms'  '      9 ms'  '    2.11 x' 
 Object_Unconstrained        1000000     '    437 ms'  '     28 ms'  '     14 ms'  '    2.00 x' 
 Object_Constrained          1000000     '    653 ms'  '     46 ms'  '     37 ms'  '    1.24 x' 
 Object_Vector3              1000000     '    201 ms'  '     22 ms'  '     12 ms'  '    1.83 x' 
 Object_Box3D                1000000     '    961 ms'  '     37 ms'  '     19 ms'  '    1.95 x' 
 Object_Recursive            1000000     '   3715 ms'  '    363 ms'  '    174 ms'  '    2.09 x' 
 Tuple_Primitive             1000000     '    107 ms'  '     23 ms'  '     11 ms'  '    2.09 x' 
 Tuple_Object                1000000     '    375 ms'  '     28 ms'  '     15 ms'  '    1.87 x' 
 Composite_Intersect         1000000     '    377 ms'  '     22 ms'  '     12 ms'  '    1.83 x' 
 Composite_Union             1000000     '    337 ms'  '     30 ms'  '     17 ms'  '    1.76 x' 
 Math_Vector4                1000000     '    137 ms'  '     23 ms'  '     11 ms'  '    2.09 x' 
 Math_Matrix4                1000000     '    576 ms'  '     37 ms'  '     28 ms'  '    1.32 x' 
 Array_Primitive_Number      1000000     '    145 ms'  '     23 ms'  '     12 ms'  '    1.92 x' 
 Array_Primitive_String      1000000     '    152 ms'  '     22 ms'  '     13 ms'  '    1.69 x' 
 Array_Primitive_Boolean     1000000     '    131 ms'  '     20 ms'  '     13 ms'  '    1.54 x' 
 Array_Object_Unconstrained  1000000     '   2821 ms'  '     62 ms'  '     45 ms'  '    1.38 x' 
 Array_Object_Constrained    1000000     '   2958 ms'  '    119 ms'  '    134 ms'  '    0.89 x' 
 Array_Object_Recursive      1000000     '  14695 ms'  '   1621 ms'  '    635 ms'  '    2.55 x' 
 Array_Tuple_Primitive       1000000     '    478 ms'  '     35 ms'  '     28 ms'  '    1.25 x' 
 Array_Tuple_Object          1000000     '   1623 ms'  '     63 ms'  '     48 ms'  '    1.31 x' 
 Array_Composite_Intersect   1000000     '   1582 ms'  '     43 ms'  '     30 ms'  '    1.43 x' 
 Array_Composite_Union       1000000     '   1331 ms'  '     76 ms'  '     40 ms'  '    1.90 x' 
 Array_Math_Vector4          1000000     '    564 ms'  '     38 ms'  '     24 ms'  '    1.58 x' 
 Array_Math_Matrix4          1000000     '   2382 ms'  '    111 ms'  '     83 ms'  '    1.34 x' 
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘

Compression

The following table lists esbuild compiled and minified sizes for each TypeBox module.

┌──────────────────────┬────────────┬────────────┬─────────────┐
 (index)               Compiled    Minified    Compression 
├──────────────────────┼────────────┼────────────┼─────────────┤
 typebox/compiler      '122.4 kb'  ' 53.4 kb'  '2.29 x'    
 typebox/errors        ' 67.6 kb'  ' 29.6 kb'  '2.28 x'    
 typebox/syntax        '132.9 kb'  ' 54.2 kb'  '2.45 x'    
 typebox/system        '  7.4 kb'  '  3.2 kb'  '2.33 x'    
 typebox/value         '150.1 kb'  ' 62.2 kb'  '2.41 x'    
 typebox               '106.8 kb'  ' 43.2 kb'  '2.47 x'    
└──────────────────────┴────────────┴────────────┴─────────────┘

Back to Home