Last active
December 9, 2015 19:18
-
-
Save nickserv/4316036 to your computer and use it in GitHub Desktop.
Example: Ruby Benchmark
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
require 'benchmark' | |
Benchmark.bm do |b| | |
b.report "summation equation" do | |
sum = 1_000_000*(1_000_000+1)/2.to_f | |
end | |
b.report "each loop" do | |
sum = 0 | |
(1..1_000_000).each { |n| sum += n } | |
end | |
b.report "for loop" do | |
sum = 0 | |
for n in 1..1_000_000 | |
sum += n | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment