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

Pull in cop benchmarks into the repo itself #467

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Earlopain
Copy link
Contributor

Looking through issues and pull requests to understand context is no fun. Allows easy checking if a cop is still relevant and properly documents why a cop exists.

I'd appreciate some feedback on the format if anyone got some. I'm not entirely convinced yet myself:

# frozen_string_literal: true

require_relative 'helper'

# https://github.com/rubocop/rubocop-performance/pull/92

umethod = String.instance_method(:start_with?)
bench_perf_and_mem(result: <<~RESULT) do |x|
  ********* IPS *********
  ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-linux]
  Warming up --------------------------------------
             bind.call   592.951k i/100ms
             bind_call     1.151M i/100ms
  Calculating -------------------------------------
             bind.call      5.925M (± 0.5%) i/s  (168.78 ns/i) -     29.648M in   5.003961s
             bind_call     11.575M (± 1.4%) i/s   (86.40 ns/i) -     58.722M in   5.074287s
  
  Comparison:
             bind_call: 11574705.6 i/s
             bind.call:  5924959.7 i/s - 1.95x  slower
  
  ********* MEMORY *********
  Calculating -------------------------------------
             bind.call    80.000  memsize (     0.000  retained)
                           1.000  objects (     0.000  retained)
                           0.000  strings (     0.000  retained)
             bind_call     0.000  memsize (     0.000  retained)
                           0.000  objects (     0.000  retained)
                           0.000  strings (     0.000  retained)
  
  Comparison:
             bind_call:          0 allocated
             bind.call:         80 allocated - Infx more
RESULT
  x.report('bind.call') { umethod.bind('hello, world').call('hello') }
  x.report('bind_call') { umethod.bind_call('hello, world', 'hello') }
end

Draft for now, pulling these all an is a bit of a chore. I plan to add remaining ones over time.

Looking through issues and pull requests to understand context is no fun
Allows easy checking if a cop is still relevant and properly documents
why a cop exists
@Earlopain
Copy link
Contributor Author

@koic would you merge this when finished? For example, you could have added the benchmark from #469 here: https://github.com/rubocop/rubocop-performance/blob/8003a18f36f0d14522a46e55768bca6e6de2ee1b/bench/big_decimal_with_numeric_argument.rb

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.

1 participant