davidmdm / myzod

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Readme] Versus Zod

c0ncentus opened this issue · comments

Hi,

in the title is "myzod" => why ?

It's write myZode is faster with Node v13 ... :

  • why not using node v4 ? if you make benchmarks, please make an update on node version and specify the version of Zod/Myzod ...
  • list advantage / drawbacks with zod rathen that saying "hey! I m faster ! Look at me ..."
    as nerd I have no time for dig into every node_modules tool that exist [...].

more transparency leads more trust.

Hi @c0ncentus!

I will redirect you to a similar request and my response.

I should take the time to update the readme, but since Zod is honestly just so popular there's no point trying to compete with it anymore, I haven't taken the time to get around to it. However since this is the second request to update the readme, I shall prioritize it soon.

It is true that Zod has increased it's performance recently in the V3 version. At the time zod and myzod were both developed myzod was sometimes 2 orders of magnitude faster. That is less true today. However there's a nice project benchmarking various validators of which zod and myzod are both nowhere near the top in terms of measuring raw performance.

Here are the results of running the zod and myzod testsuites today:

npm run start run zod myzod

Output:

> typescript-runtime-type-benchmarks@1.0.0 start
> ts-node index.ts run zod myzod

Removing previous results
Executing "zod"
Loading "zod"
Running "parseSafe" suite...
Progress: 100%

  zod:
    584 176 ops/s, ±1.60%   | fastest

Finished 1 case!
Running "parseStrict" suite...
Progress: 100%

  zod:
    560 481 ops/s, ±1.05%   | fastest

Finished 1 case!
Running "assertLoose" suite...
Progress: 100%

  zod:
    558 031 ops/s, ±0.98%   | fastest

Finished 1 case!
Running "assertStrict" suite...
Progress: 100%

  zod:
    540 034 ops/s, ±1.02%   | fastest

Finished 1 case!
Executing "myzod"
Loading "myzod"
Running "parseSafe" suite...
Progress: 100%

  myzod:
    1 830 809 ops/s, ±1.38%   | fastest

Finished 1 case!
Running "parseStrict" suite...
Progress: 100%

  myzod:
    2 086 317 ops/s, ±0.79%   | fastest

Finished 1 case!
Running "assertStrict" suite...
Progress: 100%

  myzod:
    2 068 077 ops/s, ±1.12%   | fastest

Finished 1 case!

So as it stands today myzod is roughly 4x more performant than zod using node 20.

If you are running a service and find that it is using a lot of CPU and find that your profiles are pointing to zod, myzod if a very similar alternative that could solve your performance issues. However many new projects exist that should be worth considering as well.

Best of luck!

FYI: It looks like most of the "fastest ones" require you to touch your build pipeline to transpile your typescript differently, which I assume is not for everybody.

The fastest one as of writing that doesn't require build changes but still lives in th same "order of magnitude" regarding speed currently is rescript-schema, and they have a nice tale with some other relevant attributes:
https://github.com/DZakh/rescript-schema/blob/main/docs/js-usage.md#comparison

(and myzod is in the next available "order of magnitude" regarding speed, and zod in the category after that)

With "order of magnitude" I'm referring to the number of digits in the ops/sec.