Created
June 23, 2012 03:02
-
-
Save niku/2976516 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' | |
Benchmark.bmbm do |x| | |
x.report(' 10000 times << e ') do | |
(1..10000).reduce([]) { |m,e| m << e } | |
end | |
x.report(' 10000 times + [e]') do | |
(1..10000).reduce([]) { |m,e| m + [e] } | |
end | |
x.report('100000 times << e ') do | |
(1..100000).reduce([]) { |m,e| m << e } | |
end | |
x.report('100000 times + [e]') do | |
(1..100000).reduce([]) { |m,e| m + [e] } | |
end | |
end | |
__END__ | |
Rehearsal ------------------------------------------------------ | |
10000 times << e 0.000000 0.000000 0.000000 ( 0.002595) | |
10000 times + [e] 0.160000 0.060000 0.220000 ( 0.217014) | |
100000 times << e 0.020000 0.000000 0.020000 ( 0.024962) | |
100000 times + [e] 18.610000 4.610000 23.220000 ( 23.347206) | |
-------------------------------------------- total: 23.460000sec | |
user system total real | |
10000 times << e 0.000000 0.000000 0.000000 ( 0.002796) | |
10000 times + [e] 0.150000 0.060000 0.210000 ( 0.209745) | |
100000 times << e 0.020000 0.000000 0.020000 ( 0.019664) | |
100000 times + [e] 18.540000 4.610000 23.150000 ( 23.283475) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment