Created
May 15, 2013 19:30
-
-
Save eam/5586648 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
$ ./bench_array_join.rb | |
user system total real | |
a[a.length, 0] 0.010000 0.000000 0.010000 ( 0.012573) | |
a += b 3.240000 10.560000 13.800000 ( 50.623165) | |
a.push *b 0.010000 0.000000 0.010000 ( 0.026780) | |
$ cat bench_array_join.rb | |
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'benchmark' | |
n = 20_000 | |
b = 8,9,10,11,12,13 | |
Benchmark.bm(10) do |x| | |
x.report("a[a.length, 0]") { a = 1,2,3,4,5,6,7; n.times do; a[a.length, 0] = b; end } | |
x.report("a += b") { a = 1,2,3,4,5,6,7; n.times do; a += b; end } | |
x.report("a.push *b"){ a = 1,2,3,4,5,6,7; n.times do; a.push *b; end } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment