Created
June 2, 2014 02:27
-
-
Save keichan34/5c011dcd7f99d1a34e7c 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
#!/usr/bin/env ruby | |
require 'benchmark' | |
Benchmark.bmbm do |x| | |
x.report("Push x2") do | |
ary = [] | |
100000.times do | |
ary << 'hi' | |
ary << 'hihi' | |
end | |
end | |
x.report("Concat ary") do | |
ary = [] | |
100000.times do | |
ary += ['hi', 'hihi'] | |
end | |
end | |
end |
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
# Ruby 2.1.2 | |
$ ruby ./array_benchmarks.rb | |
Rehearsal ---------------------------------------------- | |
Push x2 0.030000 0.010000 0.040000 ( 0.040183) | |
Concat ary 20.480000 19.230000 39.710000 ( 39.916032) | |
------------------------------------ total: 39.750000sec | |
user system total real | |
Push x2 0.030000 0.000000 0.030000 ( 0.026020) | |
Concat ary 19.810000 18.560000 38.370000 ( 38.427382) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment