Created
February 13, 2014 14:57
-
-
Save arthurnn/8976458 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
arr = (1..100).to_a | |
Benchmark.bm(20) do |x| | |
x.report("each.with_index") do | |
100_000.times do | |
arr.each_with_index do |v, i| | |
end | |
end | |
end | |
x.report("each.with_index b&") do | |
100_000.times do | |
bv = arr.each.with_index | |
arr.length.times do |i| | |
bv.next | |
end | |
end | |
end | |
end |
Author
arthurnn
commented
Feb 13, 2014
user system total real
each.with_index 0.780000 0.000000 0.780000 ( 0.787362)
each.with_index b& 7.700000 1.980000 9.680000 ( 9.699257)
Seems a Fiber adds about 1 ms per call. Wonder what this would look like if you compared Fibers against Threads.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment