Last active
November 17, 2018 15:34
-
-
Save matugm/64fe14666a216a1beaea5ef32a08ef01 to your computer and use it in GitHub Desktop.
Benchmarks
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
def a | |
t = Time.now | |
Array.new(10_000_000) { rand } | |
puts Time.now - t | |
end | |
10.times { a } |
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
def a | |
t = Time.now | |
10_000_000.times { "abcdefg".upcase } | |
puts Time.now - t | |
end | |
10.times { a } |
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
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 } |
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
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 } |
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
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 } |
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
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