-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
UnboundMethod#bind_call #77
Labels
Comments
koic
added a commit
to koic/rubocop-performance
that referenced
this issue
Jan 7, 2020
Fixes rubocop#77. This PR adds new `Performance/BindCall` cop. In Ruby 2.7, `UnboundMethod#bind_call` have been added. - https://bugs.ruby-lang.org/issues/15955 - ruby/ruby@83c6a1e The `bind_call(obj, args, ...)` method is faster than `bind(obj).call(args, ...)`. ```console % ruby -v ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin17] % gem i benchmark-ips (snip) % cat bench.rb require 'benchmark/ips' Benchmark.ips do |x| umethod = String.instance_method(:start_with?) x.report('bind.call') { umethod.bind('hello, world').call('hello') } x.report('bind_call') { umethod.bind_call('hello, world', 'hello') } x.compare! end % ruby bench.rb Warming up -------------------------------------- bind.call 122.167k i/100ms bind_call 189.749k i/100ms Calculating ------------------------------------- bind.call 1.795M (± 1.7%) i/s - 9.040M in 5.039135s bind_call 3.756M (± 2.2%) i/s - 18.785M in 5.004573s Comparison: bind_call: 3755510.3 i/s bind.call: 1794560.4 i/s - 2.09x slower ```
koic
added a commit
to koic/rubocop-performance
that referenced
this issue
Jan 7, 2020
Fixes rubocop#77. This PR adds new `Performance/BindCall` cop. In Ruby 2.7, `UnboundMethod#bind_call` has been added. - https://bugs.ruby-lang.org/issues/15955 - ruby/ruby@83c6a1e The `bind_call(obj, args, ...)` method is faster than `bind(obj).call(args, ...)`. ```console % ruby -v ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin17] % gem i benchmark-ips (snip) % cat bench.rb require 'benchmark/ips' Benchmark.ips do |x| umethod = String.instance_method(:start_with?) x.report('bind.call') { umethod.bind('hello, world').call('hello') } x.report('bind_call') { umethod.bind_call('hello, world', 'hello') } x.compare! end % ruby bench.rb Warming up -------------------------------------- bind.call 122.167k i/100ms bind_call 189.749k i/100ms Calculating ------------------------------------- bind.call 1.795M (± 1.7%) i/s - 9.040M in 5.039135s bind_call 3.756M (± 2.2%) i/s - 18.785M in 5.004573s Comparison: bind_call: 3755510.3 i/s bind.call: 1794560.4 i/s - 2.09x slower ```
koic
added a commit
to koic/rubocop-performance
that referenced
this issue
Jan 7, 2020
Fixes rubocop#77. This PR adds new `Performance/BindCall` cop. In Ruby 2.7, `UnboundMethod#bind_call` has been added. - https://bugs.ruby-lang.org/issues/15955 - ruby/ruby@83c6a1e The `bind_call(obj, args, ...)` method is faster than `bind(obj).call(args, ...)`. ```console % ruby -v ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin17] % gem i benchmark-ips (snip) % cat bench.rb require 'benchmark/ips' Benchmark.ips do |x| umethod = String.instance_method(:start_with?) x.report('bind.call') { umethod.bind('hello, world').call('hello') } x.report('bind_call') { umethod.bind_call('hello, world', 'hello') } x.compare! end % ruby bench.rb Warming up -------------------------------------- bind.call 122.167k i/100ms bind_call 189.749k i/100ms Calculating ------------------------------------- bind.call 1.795M (± 1.7%) i/s - 9.040M in 5.039135s bind_call 3.756M (± 2.2%) i/s - 18.785M in 5.004573s Comparison: bind_call: 3755510.3 i/s bind.call: 1794560.4 i/s - 2.09x slower ```
koic
added a commit
to koic/rubocop-performance
that referenced
this issue
Jan 7, 2020
Fixes rubocop#77. This PR adds new `Performance/BindCall` cop. In Ruby 2.7, `UnboundMethod#bind_call` has been added. - https://bugs.ruby-lang.org/issues/15955 - ruby/ruby@83c6a1e The `bind_call(obj, args, ...)` method is faster than `bind(obj).call(args, ...)`. ```console % ruby -v ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin17] % gem i benchmark-ips (snip) % cat bench.rb require 'benchmark/ips' Benchmark.ips do |x| umethod = String.instance_method(:start_with?) x.report('bind.call') { umethod.bind('hello, world').call('hello') } x.report('bind_call') { umethod.bind_call('hello, world', 'hello') } x.compare! end % ruby bench.rb Warming up -------------------------------------- bind.call 122.167k i/100ms bind_call 189.749k i/100ms Calculating ------------------------------------- bind.call 1.795M (± 1.7%) i/s - 9.040M in 5.039135s bind_call 3.756M (± 2.2%) i/s - 18.785M in 5.004573s Comparison: bind_call: 3755510.3 i/s bind.call: 1794560.4 i/s - 2.09x slower ```
koic
added a commit
that referenced
this issue
Jan 8, 2020
[Fix #77] Add new `Performance/BindCall` cop
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
Added
umethod.bind_call(obj, ...)
for faster replacement ofumethod.bind(obj).call(...)
in Ruby 2.7.See https://bugs.ruby-lang.org/issues/15955 for details.
Describe the solution you'd like
Suggest
bind_call(obj, ...)
whenbind(obj).call(...)
used.The text was updated successfully, but these errors were encountered: