Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint performance slower than biome and even slower than Prettier #35

Closed
dalisoft opened this issue Apr 4, 2024 · 14 comments
Closed

Lint performance slower than biome and even slower than Prettier #35

dalisoft opened this issue Apr 4, 2024 · 14 comments

Comments

@dalisoft
Copy link

dalisoft commented Apr 4, 2024

I am creating all-in-one linter (yes, another one) and found dprint-plugin-json slower than biome (even both written in Rust) and even slower than Prettier.
Here benchmark repo: https://github.com/dalisoft/json-lint-benchmark

Here project which does JSON linting/formatting very fast: https://github.com/jsona/jsona
I am migrated project into JS ecosystem by using download binary method, see at here if you want check

package-lock.json

| Command                                                                        |    Mean [ms] | Min [ms] | Max [ms] |     Relative |
| :----------------------------------------------------------------------------- | -----------: | -------: | -------: | -----------: |
| `biome format data/package-lock-test.json`                                     |   45.7 ± 1.2 |     44.7 |     47.0 |  7.18 ± 0.30 |
| `prettier -c data/package-lock-test.json`                                      |  154.1 ± 2.4 |    152.2 |    156.8 | 24.21 ± 0.87 |
| `dprint check data/package-lock-test.json`                                     | 199.3 ± 13.5 |    190.0 |    214.7 | 31.31 ± 2.35 |
| `deno fmt data/package-lock-test.json`                                         |    7.2 ± 0.3 |      6.8 |      7.4 |  1.13 ± 0.06 |
| `jsona fmt --option trailing_newline=true --check data/package-lock-test.json` |    6.4 ± 0.2 |      6.1 |      6.5 |         1.00 |
| `spectral lint --ignore-unknown-format data/package-lock-test.json`            |  372.1 ± 3.8 |    367.8 |    374.7 | 58.47 ± 1.99 |

package.json

| Command                                                                       |    Mean [ms] | Min [ms] | Max [ms] |      Relative |
| :---------------------------------------------------------------------------- | -----------: | -------: | -------: | ------------: |
| `biome format data/package-template.json`                                     |   48.5 ± 9.3 |     42.9 |     59.2 |   9.36 ± 7.25 |
| `prettier -c data/package-template.json`                                      |  109.5 ± 1.9 |    108.2 |    111.7 | 21.13 ± 15.85 |
| `dprint check data/package-template.json`                                     | 197.0 ± 15.9 |    187.0 |    215.3 | 38.01 ± 28.67 |
| `deno fmt data/package-template.json`                                         |  21.1 ± 23.9 |      6.9 |     48.7 |   4.08 ± 5.53 |
| `jsona fmt --option trailing_newline=true --check data/package-template.json` |    5.2 ± 3.9 |      2.4 |      9.6 |          1.00 |
| `spectral lint --ignore-unknown-format data/package-template.json`            | 410.3 ± 88.6 |    358.9 |    512.6 | 79.16 ± 61.78 |
@dsherret
Copy link
Member

dsherret commented Apr 4, 2024

That's not an accurate measurement of the performance of this crate because that's being run through dprint's CLI. What you're actually mostly measuring is the dprint CLI's baseline startup and exit time. For example, if you use dprint check --log-level=debug data/package-lock-test.json you'll see it's actually not even formatting with this crate and instead reading from the incremental cache then writing it back out. That said, I could lower the dprint CLI's baseline startup time, but it's practically already super fast in most scenarios.

If you want to measure performance of this crate then you need to run it directly (on my machine it formats those files in ~0-2ms).

@dalisoft
Copy link
Author

dalisoft commented Apr 5, 2024

@dsherret Thank you for feedback. Actually, the project reason is just lint, not format.

Can you please fix benchmarking then or how i can improve dprint CLI startup time? Because many of times CLI used to lint on lint-staged, pre-push hooks and on CI

@dsherret
Copy link
Member

dsherret commented Apr 5, 2024

Can you please fix benchmarking then or how i can improve dprint CLI startup time? Because many of times CLI used to lint on lint-staged, pre-push hooks and on CI

What that benchmark has shown is that all of them are sub 400ms which is practically very good when executing from the command line like that or running in a CI. What should matter is very large file formatting times (which this crate is not especially good at) and performance of formatting many files (which the dprint CLI is very good at, especially once the incremental cache is in place--this can be cached on a CI dprint/dprint#740).

Can you please fix benchmarking then

I don't have time to fix the benchmark and I'd recommend removing dprint-plugin-json from the benchmark since it's not even executed in it (since the warmup will cause the result to be cached). For example, if you add deno fmt --check ./data/package-lock-test.json it will be really fast because that's using an incremental cache too, but that has a faster startup time than dprint because it doesn't need to instantiate web assembly plugins.

Going to close this one.

@dsherret dsherret closed this as not planned Won't fix, can't repro, duplicate, stale Apr 5, 2024
@dsherret
Copy link
Member

dsherret commented Apr 5, 2024

Meant to say deno fmt --check ./data/package-lock-test.json in my last comment instead of dprint. Corrected.

@dalisoft
Copy link
Author

dalisoft commented Apr 5, 2024

Sorry then for disturbing you @dsherret

Unfortunately i didn't found any reference to deno fmt --check at https://dprint.dev/cli
Also there no info about what difference between dprint check and dprint fmt --check, how performance could be affected when running one of these.
How it could be optimized?
Why it loads WebAssembly when using check and why it not loads when fmt --check (if i understand correctly)?

The addition on documentations about these differences could help users choose proper way to use your CLI

Thanks

@dsherret
Copy link
Member

dsherret commented Apr 5, 2024

I meant deno fmt --check (notice deno not dprint). It uses this crate too and you can see the performance is better than the original benchmark (which helps show why I don't think the benchmark is an accurate representation of this crate):

% ./benchmark.sh
Benchmark 1: biome check data/package-template.json
  Time (mean ± σ):      35.8 ms ±   0.2 ms    [User: 29.4 ms, System: 6.2 ms]
  Range (min … max):    35.4 ms …  36.1 ms    10 runs
 
Benchmark 2: prettier -c data/package-template.json
  Time (mean ± σ):      97.7 ms ±   1.1 ms    [User: 91.7 ms, System: 7.1 ms]
  Range (min … max):    96.1 ms …  99.4 ms    10 runs
 
Benchmark 3: dprint check --incremental=false data/package-template.json
  Time (mean ± σ):     181.5 ms ±   2.6 ms    [User: 130.2 ms, System: 12.6 ms]
  Range (min … max):   178.8 ms … 187.8 ms    10 runs
 
Benchmark 4: jsona fmt --option trailing_newline=true --check data/package-template.json
  Time (mean ± σ):       2.0 ms ±   0.1 ms    [User: 1.3 ms, System: 0.9 ms]
  Range (min … max):     1.8 ms …   2.2 ms    10 runs
 
  Warning: Command took less than 5 ms to complete. Note that the results might be inaccurate because hyperfine can not calibrate the shell startup time much more precise than this limit. You can try to use the `-N`/`--shell=none` option to disable the shell completely.
 
Benchmark 5: deno fmt --check data/package-template.json
  Time (mean ± σ):       5.8 ms ±   0.2 ms    [User: 3.5 ms, System: 2.2 ms]
  Range (min … max):     5.4 ms …   6.1 ms    10 runs
 
Benchmark 6: spectral lint --ignore-unknown-format data/package-template.json
  Time (mean ± σ):     304.0 ms ±   3.4 ms    [User: 379.8 ms, System: 35.4 ms]
  Range (min … max):   300.8 ms … 312.2 ms    10 runs
 
Summary
  jsona fmt --option trailing_newline=true --check data/package-template.json ran
    2.86 ± 0.18 times faster than deno fmt --check data/package-template.json
   17.63 ± 1.00 times faster than biome check data/package-template.json
   48.08 ± 2.76 times faster than prettier -c data/package-template.json
   89.28 ± 5.19 times faster than dprint check --incremental=false data/package-template.json
  149.53 ± 8.59 times faster than spectral lint --ignore-unknown-format data/package-template.json
Benchmark 1: biome check data/package-lock-test.json
  Time (mean ± σ):      44.1 ms ±   0.4 ms    [User: 36.6 ms, System: 7.0 ms]
  Range (min … max):    43.6 ms …  45.0 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 2: prettier -c data/package-lock-test.json
  Time (mean ± σ):     134.9 ms ±   2.0 ms    [User: 200.9 ms, System: 10.0 ms]
  Range (min … max):   132.7 ms … 139.6 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 3: dprint check --incremental=false data/package-lock-test.json
  Time (mean ± σ):     187.0 ms ±   3.6 ms    [User: 133.8 ms, System: 12.9 ms]
  Range (min … max):   183.8 ms … 195.8 ms    10 runs
 
Benchmark 4: jsona fmt --option trailing_newline=true --check data/package-lock-test.json
  Time (mean ± σ):       5.4 ms ±   0.3 ms    [User: 4.1 ms, System: 1.2 ms]
  Range (min … max):     5.0 ms …   5.9 ms    10 runs
 
  Warning: Command took less than 5 ms to complete. Note that the results might be inaccurate because hyperfine can not calibrate the shell startup time much more precise than this limit. You can try to use the `-N`/`--shell=none` option to disable the shell completely.
 
Benchmark 5: deno fmt --check data/package-lock-test.json
  Time (mean ± σ):      12.5 ms ±   2.5 ms    [User: 7.5 ms, System: 3.6 ms]
  Range (min … max):    10.5 ms …  19.2 ms    10 runs
 
Benchmark 6: spectral lint --ignore-unknown-format data/package-lock-test.json
  Time (mean ± σ):     316.6 ms ±   5.3 ms    [User: 399.1 ms, System: 37.2 ms]
  Range (min … max):   311.4 ms … 328.6 ms    10 runs
 
Summary
  jsona fmt --option trailing_newline=true --check data/package-lock-test.json ran
    2.32 ± 0.48 times faster than deno fmt --check data/package-lock-test.json
    8.16 ± 0.45 times faster than biome check data/package-lock-test.json
   24.96 ± 1.41 times faster than prettier -c data/package-lock-test.json
   34.60 ± 2.00 times faster than dprint check --incremental=false data/package-lock-test.json
   58.58 ± 3.35 times faster than spectral lint --ignore-unknown-format data/package-lock-test.json
Benchmark 1: biome check data/twitter.json
  Time (mean ± σ):     119.9 ms ±   1.1 ms    [User: 107.6 ms, System: 11.5 ms]
  Range (min … max):   118.7 ms … 122.2 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 2: prettier -c data/twitter.json
  Time (mean ± σ):     274.9 ms ±   3.2 ms    [User: 493.3 ms, System: 23.3 ms]
  Range (min … max):   271.3 ms … 281.2 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 3: dprint check --incremental=false data/twitter.json
  Time (mean ± σ):     225.2 ms ±   2.4 ms    [User: 172.0 ms, System: 14.7 ms]
  Range (min … max):   221.8 ms … 229.9 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 4: jsona fmt --option trailing_newline=true --check data/twitter.json
  Time (mean ± σ):      31.9 ms ±   0.6 ms    [User: 29.7 ms, System: 1.8 ms]
  Range (min … max):    31.5 ms …  33.6 ms    10 runs
 
Benchmark 5: deno fmt --check data/twitter.json
  Time (mean ± σ):      89.6 ms ±   2.0 ms    [User: 77.9 ms, System: 9.5 ms]
  Range (min … max):    87.0 ms …  93.4 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 6: spectral lint --ignore-unknown-format data/twitter.json
  Time (mean ± σ):     376.5 ms ±   7.3 ms    [User: 523.7 ms, System: 39.9 ms]
  Range (min … max):   368.6 ms … 389.5 ms    10 runs
 
Summary
  jsona fmt --option trailing_newline=true --check data/twitter.json ran
    2.81 ± 0.08 times faster than deno fmt --check data/twitter.json
    3.76 ± 0.08 times faster than biome check data/twitter.json
    7.06 ± 0.15 times faster than dprint check --incremental=false data/twitter.json
    8.62 ± 0.19 times faster than prettier -c data/twitter.json
   11.80 ± 0.32 times faster than spectral lint --ignore-unknown-format data/twitter.json

Needed to set a --prepare in hyperfine to delete Deno's formatting cache:

hyperfine --runs 10 --prepare "rm /Users/david/Library/Caches/deno/fmt_incremental_cache_v1 || true" --warmup 3 "biome check $file" "prettier -c $file" "dprint check --incremental=false $file" "jsona fmt --option trailing_newline=true --check $file" "deno fmt --check $file" "spectral lint --ignore-unknown-format $file" --export-markdown "results/$item.md" --ignore-failure

@dalisoft
Copy link
Author

dalisoft commented Apr 5, 2024

Yeah, seems i wrong read deno fmt and used dprint fmt instead. Seems dprint fmt faster but it formatting files too. I want only lint, so what proper way you recommend me to use? Without using deno please

Anyway, thank you for reply and sorry for issue which i'm made wrong (maybe because of i didn't read docs good?)

@dsherret
Copy link
Member

dsherret commented Apr 5, 2024

Yeah, seems i wrong read deno fmt and used deno fmt instead. Seems deno fmt faster but it formatting files too. I want only lint, so what proper way you recommend me to use? Without using deno please

The --check flag in deno fmt --check causes it to lint instead of format.

@dalisoft
Copy link
Author

dalisoft commented Apr 5, 2024

Updated previous my comment. Is there any such flag for dprint fmt?

@dsherret
Copy link
Member

dsherret commented Apr 5, 2024

Sorry, I misunderstood. dprint check will check if a file is formatted and output a diff if not, as the benchmark is doing.

@dalisoft
Copy link
Author

dalisoft commented Apr 5, 2024

Thank you. So benchmark CLI command used for dprint in benchmark is not wrong then

@dsherret
Copy link
Member

dsherret commented Apr 5, 2024

@dalisoft I improved the startup time of dprint's cli on mac and linux in 0.45.1 (just released). It was unconditionally reading certificates from the system on startup for https requests, which was fast on windows, but not on mac.

% ./benchmark.sh
Benchmark 1: biome check data/package-template.json
  Time (mean ± σ):      35.3 ms ±   1.0 ms    [User: 28.9 ms, System: 6.6 ms]
  Range (min … max):    34.6 ms …  37.3 ms    10 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: prettier -c data/package-template.json
  Time (mean ± σ):      93.8 ms ±   1.5 ms    [User: 88.1 ms, System: 7.1 ms]
  Range (min … max):    91.9 ms …  96.5 ms    10 runs
 
Benchmark 3: dprint check --incremental=false data/package-template.json
  Time (mean ± σ):      37.7 ms ±   0.3 ms    [User: 29.6 ms, System: 6.3 ms]
  Range (min … max):    37.5 ms …  38.4 ms    10 runs
 
Benchmark 4: jsona fmt --option trailing_newline=true --check data/package-template.json
  Time (mean ± σ):       2.0 ms ±   0.1 ms    [User: 1.2 ms, System: 0.9 ms]
  Range (min … max):     1.9 ms …   2.1 ms    10 runs
 
  Warning: Command took less than 5 ms to complete. Note that the results might be inaccurate because hyperfine can not calibrate the shell startup time much more precise than this limit. You can try to use the `-N`/`--shell=none` option to disable the shell completely.
 
Benchmark 5: deno fmt --check data/package-template.json
  Time (mean ± σ):       4.9 ms ±   0.1 ms    [User: 3.1 ms, System: 1.5 ms]
  Range (min … max):     4.7 ms …   5.1 ms    10 runs
 
  Warning: Command took less than 5 ms to complete. Note that the results might be inaccurate because hyperfine can not calibrate the shell startup time much more precise than this limit. You can try to use the `-N`/`--shell=none` option to disable the shell completely.
 
Benchmark 6: spectral lint --ignore-unknown-format data/package-template.json
  Time (mean ± σ):     295.8 ms ±   3.0 ms    [User: 368.8 ms, System: 36.6 ms]
  Range (min … max):   292.3 ms … 301.0 ms    10 runs
 
Summary
  jsona fmt --option trailing_newline=true --check data/package-template.json ran
    2.40 ± 0.10 times faster than deno fmt --check data/package-template.json
   17.41 ± 0.78 times faster than biome check data/package-template.json
   18.58 ± 0.65 times faster than dprint check --incremental=false data/package-template.json
   46.25 ± 1.74 times faster than prettier -c data/package-template.json
  145.83 ± 5.21 times faster than spectral lint --ignore-unknown-format data/package-template.json
Benchmark 1: biome check data/package-lock-test.json
  Time (mean ± σ):      43.2 ms ±   1.0 ms    [User: 36.0 ms, System: 7.3 ms]
  Range (min … max):    42.5 ms …  45.8 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: prettier -c data/package-lock-test.json
  Time (mean ± σ):     130.8 ms ±   0.7 ms    [User: 195.5 ms, System: 10.5 ms]
  Range (min … max):   130.1 ms … 132.0 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 3: dprint check --incremental=false data/package-lock-test.json
  Time (mean ± σ):      41.8 ms ±   0.7 ms    [User: 33.0 ms, System: 7.0 ms]
  Range (min … max):    40.9 ms …  43.1 ms    10 runs
 
Benchmark 4: jsona fmt --option trailing_newline=true --check data/package-lock-test.json
  Time (mean ± σ):       4.6 ms ±   0.1 ms    [User: 3.4 ms, System: 1.2 ms]
  Range (min … max):     4.5 ms …   4.8 ms    10 runs
 
  Warning: Command took less than 5 ms to complete. Note that the results might be inaccurate because hyperfine can not calibrate the shell startup time much more precise than this limit. You can try to use the `-N`/`--shell=none` option to disable the shell completely.
 
Benchmark 5: deno fmt --check data/package-lock-test.json
  Time (mean ± σ):       8.1 ms ±   0.1 ms    [User: 5.9 ms, System: 1.8 ms]
  Range (min … max):     7.9 ms …   8.4 ms    10 runs
 
Benchmark 6: spectral lint --ignore-unknown-format data/package-lock-test.json
  Time (mean ± σ):     305.4 ms ±   2.6 ms    [User: 386.4 ms, System: 36.9 ms]
  Range (min … max):   302.2 ms … 310.9 ms    10 runs
 
Summary
  jsona fmt --option trailing_newline=true --check data/package-lock-test.json ran
    1.75 ± 0.04 times faster than deno fmt --check data/package-lock-test.json
    9.04 ± 0.21 times faster than dprint check --incremental=false data/package-lock-test.json
    9.34 ± 0.27 times faster than biome check data/package-lock-test.json
   28.26 ± 0.51 times faster than prettier -c data/package-lock-test.json
   66.00 ± 1.26 times faster than spectral lint --ignore-unknown-format data/package-lock-test.json
Benchmark 1: biome check data/twitter.json
  Time (mean ± σ):     119.8 ms ±   0.3 ms    [User: 106.5 ms, System: 11.5 ms]
  Range (min … max):   119.3 ms … 120.1 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 2: prettier -c data/twitter.json
  Time (mean ± σ):     271.7 ms ±   3.0 ms    [User: 490.8 ms, System: 25.4 ms]
  Range (min … max):   269.3 ms … 279.0 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 3: dprint check --incremental=false data/twitter.json
  Time (mean ± σ):      81.1 ms ±   0.5 ms    [User: 70.5 ms, System: 8.0 ms]
  Range (min … max):    80.2 ms …  81.5 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 4: jsona fmt --option trailing_newline=true --check data/twitter.json
  Time (mean ± σ):      27.0 ms ±   0.2 ms    [User: 24.9 ms, System: 1.7 ms]
  Range (min … max):    26.8 ms …  27.3 ms    10 runs
 
Benchmark 5: deno fmt --check data/twitter.json
  Time (mean ± σ):      82.2 ms ±   0.4 ms    [User: 72.7 ms, System: 7.8 ms]
  Range (min … max):    81.5 ms …  82.6 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 6: spectral lint --ignore-unknown-format data/twitter.json
  Time (mean ± σ):     356.6 ms ±   3.8 ms    [User: 502.6 ms, System: 38.6 ms]
  Range (min … max):   351.8 ms … 365.4 ms    10 runs
 
Summary
  jsona fmt --option trailing_newline=true --check data/twitter.json ran
    3.00 ± 0.03 times faster than dprint check --incremental=false data/twitter.json
    3.04 ± 0.02 times faster than deno fmt --check data/twitter.json
    4.44 ± 0.03 times faster than biome check data/twitter.json
   10.06 ± 0.13 times faster than prettier -c data/twitter.json
   13.21 ± 0.16 times faster than spectral lint --ignore-unknown-format data/twitter.json

I noticed though that in the benchmark, dprint is installed via npm. If it's installed as a binary globally instead of running through node then it's much faster:

% ./benchmark.sh
Benchmark 1: biome check data/package-template.json
  Time (mean ± σ):      34.9 ms ±   0.2 ms    [User: 28.5 ms, System: 6.3 ms]
  Range (min … max):    34.4 ms …  35.3 ms    10 runs
 
Benchmark 2: prettier -c data/package-template.json
  Time (mean ± σ):      93.9 ms ±   0.3 ms    [User: 88.0 ms, System: 7.0 ms]
  Range (min … max):    93.2 ms …  94.3 ms    10 runs
 
Benchmark 3: dprint check --incremental=false data/package-template.json
  Time (mean ± σ):       4.8 ms ±   0.1 ms    [User: 2.3 ms, System: 2.1 ms]
  Range (min … max):     4.7 ms …   5.0 ms    10 runs
 
  Warning: Command took less than 5 ms to complete. Note that the results might be inaccurate because hyperfine can not calibrate the shell startup time much more precise than this limit. You can try to use the `-N`/`--shell=none` option to disable the shell completely.
 
Benchmark 4: jsona fmt --option trailing_newline=true --check data/package-template.json
  Time (mean ± σ):       2.2 ms ±   0.3 ms    [User: 1.2 ms, System: 1.0 ms]
  Range (min … max):     1.9 ms …   3.2 ms    10 runs
 
  Warning: Command took less than 5 ms to complete. Note that the results might be inaccurate because hyperfine can not calibrate the shell startup time much more precise than this limit. You can try to use the `-N`/`--shell=none` option to disable the shell completely.
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 5: deno fmt --check data/package-template.json
  Time (mean ± σ):       4.9 ms ±   0.1 ms    [User: 3.2 ms, System: 1.5 ms]
  Range (min … max):     4.8 ms …   5.2 ms    10 runs
 
  Warning: Command took less than 5 ms to complete. Note that the results might be inaccurate because hyperfine can not calibrate the shell startup time much more precise than this limit. You can try to use the `-N`/`--shell=none` option to disable the shell completely.
 
Benchmark 6: spectral lint --ignore-unknown-format data/package-template.json
  Time (mean ± σ):     296.4 ms ±   4.7 ms    [User: 371.3 ms, System: 35.8 ms]
  Range (min … max):   290.3 ms … 305.6 ms    10 runs
 
Summary
  jsona fmt --option trailing_newline=true --check data/package-template.json ran
    2.19 ± 0.35 times faster than dprint check --incremental=false data/package-template.json
    2.23 ± 0.36 times faster than deno fmt --check data/package-template.json
   15.78 ± 2.49 times faster than biome check data/package-template.json
   42.51 ± 6.70 times faster than prettier -c data/package-template.json
  134.24 ± 21.26 times faster than spectral lint --ignore-unknown-format data/package-template.json
Benchmark 1: biome check data/package-lock-test.json
  Time (mean ± σ):      43.1 ms ±   0.3 ms    [User: 35.9 ms, System: 7.0 ms]
  Range (min … max):    42.7 ms …  43.7 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 2: prettier -c data/package-lock-test.json
  Time (mean ± σ):     131.4 ms ±   2.7 ms    [User: 197.1 ms, System: 11.0 ms]
  Range (min … max):   128.2 ms … 137.3 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 3: dprint check --incremental=false data/package-lock-test.json
  Time (mean ± σ):       8.6 ms ±   0.2 ms    [User: 5.7 ms, System: 2.4 ms]
  Range (min … max):     8.4 ms …   9.2 ms    10 runs
 
Benchmark 4: jsona fmt --option trailing_newline=true --check data/package-lock-test.json
  Time (mean ± σ):       4.6 ms ±   0.1 ms    [User: 3.4 ms, System: 1.2 ms]
  Range (min … max):     4.5 ms …   4.8 ms    10 runs
 
  Warning: Command took less than 5 ms to complete. Note that the results might be inaccurate because hyperfine can not calibrate the shell startup time much more precise than this limit. You can try to use the `-N`/`--shell=none` option to disable the shell completely.
 
Benchmark 5: deno fmt --check data/package-lock-test.json
  Time (mean ± σ):       8.0 ms ±   0.1 ms    [User: 5.9 ms, System: 1.8 ms]
  Range (min … max):     7.9 ms …   8.2 ms    10 runs
 
Benchmark 6: spectral lint --ignore-unknown-format data/package-lock-test.json
  Time (mean ± σ):     307.4 ms ±   3.3 ms    [User: 388.7 ms, System: 37.0 ms]
  Range (min … max):   301.6 ms … 313.6 ms    10 runs
 
Summary
  jsona fmt --option trailing_newline=true --check data/package-lock-test.json ran
    1.74 ± 0.05 times faster than deno fmt --check data/package-lock-test.json
    1.88 ± 0.07 times faster than dprint check --incremental=false data/package-lock-test.json
    9.37 ± 0.24 times faster than biome check data/package-lock-test.json
   28.56 ± 0.92 times faster than prettier -c data/package-lock-test.json
   66.84 ± 1.80 times faster than spectral lint --ignore-unknown-format data/package-lock-test.json
Benchmark 1: biome check data/twitter.json
  Time (mean ± σ):     119.5 ms ±   1.4 ms    [User: 106.7 ms, System: 12.0 ms]
  Range (min … max):   117.9 ms … 123.2 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 2: prettier -c data/twitter.json
  Time (mean ± σ):     271.4 ms ±   2.3 ms    [User: 488.8 ms, System: 25.8 ms]
  Range (min … max):   268.0 ms … 274.9 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 3: dprint check --incremental=false data/twitter.json
  Time (mean ± σ):      49.4 ms ±   1.3 ms    [User: 43.9 ms, System: 4.3 ms]
  Range (min … max):    48.3 ms …  52.3 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 4: jsona fmt --option trailing_newline=true --check data/twitter.json
  Time (mean ± σ):      26.7 ms ±   0.1 ms    [User: 24.9 ms, System: 1.7 ms]
  Range (min … max):    26.6 ms …  27.0 ms    10 runs
 
Benchmark 5: deno fmt --check data/twitter.json
  Time (mean ± σ):      82.5 ms ±   0.2 ms    [User: 72.7 ms, System: 8.2 ms]
  Range (min … max):    82.3 ms …  82.7 ms    10 runs
 
  Warning: Ignoring non-zero exit code.
 
Benchmark 6: spectral lint --ignore-unknown-format data/twitter.json
  Time (mean ± σ):     360.2 ms ±   9.5 ms    [User: 505.6 ms, System: 40.3 ms]
  Range (min … max):   351.2 ms … 377.2 ms    10 runs
 
Summary
  jsona fmt --option trailing_newline=true --check data/twitter.json ran
    1.85 ± 0.05 times faster than dprint check --incremental=false data/twitter.json
    3.09 ± 0.02 times faster than deno fmt --check data/twitter.json
    4.47 ± 0.06 times faster than biome check data/twitter.json
   10.16 ± 0.10 times faster than prettier -c data/twitter.json
   13.48 ± 0.36 times faster than spectral lint --ignore-unknown-format data/twitter.json

@dalisoft
Copy link
Author

dalisoft commented Apr 5, 2024

Thank you for update @dsherret
I am created new repo https://github.com/dalisoft/dprint-rs-npm using my bin2npm script and yes, it checks much faster as it links binary itself without any overhead (or almost no overhead)

@dalisoft
Copy link
Author

dalisoft commented Apr 5, 2024

Benchmark 1: biome format data/package-template.json
  Time (mean ± σ):      69.4 ms ±  48.3 ms    [User: 34.6 ms, System: 13.8 ms]
  Range (min … max):    41.4 ms … 125.2 ms    3 runs
 
Benchmark 2: prettier -c data/package-template.json
  Time (mean ± σ):     126.4 ms ±  32.9 ms    [User: 105.2 ms, System: 11.3 ms]
  Range (min … max):   106.4 ms … 164.4 ms    3 runs
 
Benchmark 3: ./node_modules/dprint/bin.js check data/package-template.json
  Time (mean ± σ):      52.8 ms ±  10.8 ms    [User: 36.5 ms, System: 10.5 ms]
  Range (min … max):    46.1 ms …  65.2 ms    3 runs
 
Benchmark 4: ./node_modules/dprint-rs-npm/dprint check data/package-template.json
  Time (mean ± σ):      12.0 ms ±   8.2 ms    [User: 3.3 ms, System: 4.9 ms]
  Range (min … max):     7.2 ms …  21.5 ms    3 runs
 
Benchmark 5: deno fmt data/package-template.json
  Time (mean ± σ):      19.8 ms ±  23.0 ms    [User: 4.5 ms, System: 4.9 ms]
  Range (min … max):     6.4 ms …  46.4 ms    3 runs
 
Benchmark 6: jsona fmt --option trailing_newline=true --check data/package-template.json
  Time (mean ± σ):       5.5 ms ±   4.1 ms    [User: 1.7 ms, System: 1.8 ms]
  Range (min … max):     2.4 ms …  10.2 ms    3 runs
 
Benchmark 7: spectral lint --ignore-unknown-format data/package-template.json
  Time (mean ± σ):     398.5 ms ±  62.7 ms    [User: 414.2 ms, System: 49.1 ms]
  Range (min … max):   360.2 ms … 470.8 ms    3 runs
 
Summary
  jsona fmt --option trailing_newline=true --check data/package-template.json ran
    2.18 ± 2.19 times faster than ./node_modules/dprint-rs-npm/dprint check data/package-template.json
    3.58 ± 4.94 times faster than deno fmt data/package-template.json
    9.54 ± 7.35 times faster than ./node_modules/dprint/bin.js check data/package-template.json
   12.55 ± 12.78 times faster than biome format data/package-template.json
   22.86 ± 17.99 times faster than prettier -c data/package-template.json
   72.08 ± 54.71 times faster than spectral lint --ignore-unknown-format data/package-template.json
Benchmark 1: biome format data/package-lock-test.json
  Time (mean ± σ):      54.4 ms ±  14.6 ms    [User: 39.9 ms, System: 9.1 ms]
  Range (min … max):    44.9 ms …  71.3 ms    3 runs
 
Benchmark 2: prettier -c data/package-lock-test.json
  Time (mean ± σ):     154.9 ms ±   3.5 ms    [User: 196.4 ms, System: 13.2 ms]
  Range (min … max):   152.5 ms … 158.9 ms    3 runs
 
Benchmark 3: ./node_modules/dprint/bin.js check data/package-lock-test.json
  Time (mean ± σ):      49.8 ms ±   1.3 ms    [User: 39.4 ms, System: 8.7 ms]
  Range (min … max):    48.9 ms …  51.3 ms    3 runs
 
Benchmark 4: ./node_modules/dprint-rs-npm/dprint check data/package-lock-test.json
  Time (mean ± σ):      10.8 ms ±   0.2 ms    [User: 6.8 ms, System: 3.3 ms]
  Range (min … max):    10.7 ms …  11.0 ms    3 runs
 
Benchmark 5: deno fmt data/package-lock-test.json
  Time (mean ± σ):       6.7 ms ±   0.4 ms    [User: 4.1 ms, System: 1.9 ms]
  Range (min … max):     6.4 ms …   7.1 ms    3 runs
 
Benchmark 6: jsona fmt --option trailing_newline=true --check data/package-lock-test.json
  Time (mean ± σ):       5.4 ms ±   0.1 ms    [User: 4.4 ms, System: 1.0 ms]
  Range (min … max):     5.4 ms …   5.5 ms    3 runs
 
Benchmark 7: spectral lint --ignore-unknown-format data/package-lock-test.json
  Time (mean ± σ):     372.5 ms ±   3.9 ms    [User: 424.5 ms, System: 42.7 ms]
  Range (min … max):   369.4 ms … 376.9 ms    3 runs
 
Summary
  jsona fmt --option trailing_newline=true --check data/package-lock-test.json ran
    1.24 ± 0.07 times faster than deno fmt data/package-lock-test.json
    1.99 ± 0.04 times faster than ./node_modules/dprint-rs-npm/dprint check data/package-lock-test.json
    9.17 ± 0.27 times faster than ./node_modules/dprint/bin.js check data/package-lock-test.json
   10.03 ± 2.70 times faster than biome format data/package-lock-test.json
   28.55 ± 0.72 times faster than prettier -c data/package-lock-test.json
   68.64 ± 1.06 times faster than spectral lint --ignore-unknown-format data/package-lock-test.json
Benchmark 1: biome format data/twitter.json
  Time (mean ± σ):      64.1 ms ±   4.5 ms    [User: 53.2 ms, System: 8.4 ms]
  Range (min … max):    60.2 ms …  69.0 ms    3 runs
 
Benchmark 2: prettier -c data/twitter.json
  Time (mean ± σ):     331.7 ms ±   2.7 ms    [User: 563.1 ms, System: 29.0 ms]
  Range (min … max):   329.1 ms … 334.5 ms    3 runs
 
Benchmark 3: ./node_modules/dprint/bin.js check data/twitter.json
  Time (mean ± σ):      88.1 ms ±   0.4 ms    [User: 76.1 ms, System: 10.0 ms]
  Range (min … max):    87.7 ms …  88.4 ms    3 runs
 
Benchmark 4: ./node_modules/dprint-rs-npm/dprint check data/twitter.json
  Time (mean ± σ):      49.4 ms ±   0.7 ms    [User: 43.9 ms, System: 5.0 ms]
  Range (min … max):    48.7 ms …  50.2 ms    3 runs
 
Benchmark 5: deno fmt data/twitter.json
  Time (mean ± σ):      42.5 ms ±   0.3 ms    [User: 37.7 ms, System: 4.5 ms]
  Range (min … max):    42.2 ms …  42.7 ms    3 runs
 
Benchmark 6: jsona fmt --option trailing_newline=true --check data/twitter.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants