Skip to content

Instantly share code, notes, and snippets.

@eam
Created May 15, 2013 19:30
Show Gist options
  • Save eam/5586648 to your computer and use it in GitHub Desktop.
Save eam/5586648 to your computer and use it in GitHub Desktop.
$ ./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