Skip to content

Changed &block method argument to yield construction#2188

Merged
mperham merged 2 commits intosidekiq:masterfrom
davydovanton:block
Feb 12, 2015
Merged

Changed &block method argument to yield construction#2188
mperham merged 2 commits intosidekiq:masterfrom
davydovanton:block

Conversation

@davydovanton
Copy link
Contributor

Hi,
As you may know yield construction more faster than &block in arguments (with block.call).
For example, for me yield faster than block to 5 times (ruby 2.1.5; you can see benchmark below).
And because that i changed &block method arguments on yield construction in all methods where block isn't need in other methods call.

Benchmarks

(all developers love benchmarks 😃)

Code for compare yield and block

require 'benchmark/ips'

def yield_proc
  yield
end

def block_proc(&block)
  block.call
end

Benchmark.ips do |x|
  x.report('yield'){ yield_proc{ 1 + 1 } }
  x.report('block'){ block_proc{ 1 + 1 } }
end

Results

Calculating -------------------------------------
               yield   128.265k i/100ms
               block    62.716k i/100ms
-------------------------------------------------
               yield      5.821M (± 5.0%) i/s -     29.116M
               block      1.079M (±24.0%) i/s -      5.143M

@mperham
Copy link
Collaborator

mperham commented Feb 12, 2015

lgtm, waiting for travis.

@davydovanton
Copy link
Contributor Author

@mperham all tests passed 🎉

mperham added a commit that referenced this pull request Feb 12, 2015
Changed &block method argument to yield construction
@mperham mperham merged commit 66f2270 into sidekiq:master Feb 12, 2015
@mperham
Copy link
Collaborator

mperham commented Feb 12, 2015

thank you!

@davydovanton
Copy link
Contributor Author

and you to 🌟

@davydovanton davydovanton deleted the block branch February 12, 2015 21:47
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.

2 participants