Guest User

Embedding vs to_s and concat

a guest
Dec 24th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.84 KB | None | 0 0
  1. def test()
  2.   10.times do
  3.     start_time = Time.now.to_f
  4.     x = []
  5.     1000000.times do |i|
  6.       x << "foo#{i}"
  7.       x << "foo#{i}"
  8.       x << "foo#{i}"
  9.       x << "foo#{i}"
  10.       x << "foo#{i}"
  11.       x << "foo#{i}"
  12.       x << "foo#{i}"
  13.       x << "foo#{i}"
  14.       x << "foo#{i}"
  15.       x << "foo#{i}"
  16.       x = []
  17.     end
  18.     end_time = Time.now.to_f
  19.     puts "Inline: #{end_time-start_time}"
  20.     start_time = Time.now.to_f
  21.     x = []
  22.     1000000.times do |i|
  23.       x << 'foo' + i.to_s
  24.       x << 'foo' + i.to_s
  25.       x << 'foo' + i.to_s
  26.       x << 'foo' + i.to_s
  27.       x << 'foo' + i.to_s
  28.       x << 'foo' + i.to_s
  29.       x << 'foo' + i.to_s
  30.       x << 'foo' + i.to_s
  31.       x << 'foo' + i.to_s
  32.       x << 'foo' + i.to_s
  33.       x = []
  34.     end
  35.     end_time = Time.now.to_f
  36.     puts "Concat: #{end_time-start_time}"
  37.   end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment