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

Automatically compute the max label width to always properly align the output #142

Merged
merged 2 commits into from
Jan 31, 2025

Conversation

eregon
Copy link
Contributor

@eregon eregon commented Jan 31, 2025

Using a variant of https://gist.github.com/eregon/27b56c686e238bafa6b46b73f17a4618
(these benchmark results are noisy, don't interpret them, it's just to show output alignment)
Before:

ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
Warming up --------------------------------------
  Prism.parse + walk     2.000 i/100ms
   Parser gem + walk     1.000 i/100ms
   RubyParser + walk     1.000 i/100ms
  Ripper.sexp + walk     1.000 i/100ms
RubyVM::AbstractSyntaxTree + walk
                         2.000 i/100ms
Calculating -------------------------------------
  Prism.parse + walk     22.541 (± 0.0%) i/s   (44.36 ms/i) -    114.000 in   5.058981s
   Parser gem + walk      1.266 (± 0.0%) i/s  (789.94 ms/i) -      7.000 in   5.529701s
   RubyParser + walk      1.172 (± 0.0%) i/s  (853.39 ms/i) -      6.000 in   5.120520s
  Ripper.sexp + walk      9.523 (± 0.0%) i/s  (105.01 ms/i) -     48.000 in   5.047729s
RubyVM::AbstractSyntaxTree + walk
                         21.209 (± 4.7%) i/s   (47.15 ms/i) -    106.000 in   5.003630s

Comparison:
  Prism.parse + walk:       22.5 i/s
RubyVM::AbstractSyntaxTree + walk:       21.2 i/s - 1.06x  slower
  Ripper.sexp + walk:        9.5 i/s - 2.37x  slower
   Parser gem + walk:        1.3 i/s - 17.81x  slower
   RubyParser + walk:        1.2 i/s - 19.24x  slower

After:

ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
Warming up --------------------------------------
               Prism.parse + walk     2.000 i/100ms
                Parser gem + walk     1.000 i/100ms
                RubyParser + walk     1.000 i/100ms
               Ripper.sexp + walk     1.000 i/100ms
RubyVM::AbstractSyntaxTree + walk     2.000 i/100ms
Calculating -------------------------------------
               Prism.parse + walk     22.261 (± 0.0%) i/s   (44.92 ms/i) -    112.000 in   5.033290s
                Parser gem + walk      1.242 (± 0.0%) i/s  (804.86 ms/i) -      7.000 in   5.636524s
                RubyParser + walk      1.156 (± 0.0%) i/s  (864.95 ms/i) -      6.000 in   5.189805s
               Ripper.sexp + walk      9.373 (± 0.0%) i/s  (106.69 ms/i) -     47.000 in   5.023535s
RubyVM::AbstractSyntaxTree + walk     21.235 (± 4.7%) i/s   (47.09 ms/i) -    108.000 in   5.090632s

Comparison:
               Prism.parse + walk:       22.3 i/s
RubyVM::AbstractSyntaxTree + walk:       21.2 i/s - 1.05x  slower
               Ripper.sexp + walk:        9.4 i/s - 2.37x  slower
                Parser gem + walk:        1.2 i/s - 17.92x  slower
                RubyParser + walk:        1.2 i/s - 19.25x  slower

Notably for the Comparison it looked not nice, and for warmup and calculating it kind of broke the flow by having extra newlines.

FWIW this is part of the benchmarks I ran for https://eregon.me/blog/2024/10/27/benchmarking-ruby-parsers.html

@nateberkopec nateberkopec merged commit a1991c9 into evanphx:master Jan 31, 2025
13 checks passed
@nateberkopec
Copy link
Collaborator

Cheers @eregon. Nice article too!

@evanphx
Copy link
Owner

evanphx commented Jan 31, 2025

👏🏻

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

Successfully merging this pull request may close these issues.

3 participants