Skip to content

Instantly share code, notes, and snippets.

@matugm matugm/array-random.rb
Last active Nov 17, 2018

Embed
What would you like to do?
Benchmarks
def a
t = Time.now
Array.new(10_000_000) { rand }
puts Time.now - t
end
10.times { a }
def a
t = Time.now
10_000_000.times { "abcdefg".upcase }
puts Time.now - t
end
10.times { a }
def a
t = Time.now
i = 1
n = 1
while i < 100_000
n *= i
n += 1
i += 1
end
n
puts Time.now - t
end
10.times { a }
def a
t = Time.now
i = 1
n = 1
while i < 10_000_000
n *= i
n %= 10000
n += 1
i += 1
end
n
puts Time.now - t
end
10.times { a }
def a
t = Time.now
i = 0
str = ""
while i < 10_000_000
i += 1
str << i.to_s
end
puts Time.now - t
end
10.times { a }
def a
t = Time.now
i = 0
while i < 10_000_000
i += 1
end
puts Time.now - t
end
10.times { a }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.