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 fizzbuzz(n) | |
(1..n).each do |i| | |
if i % 15 == 0 | |
puts 'fizzbuzz' | |
elsif i % 5 == 0 | |
puts 'buzz' | |
elsif i % 3 == 3 | |
puts 'fizz' | |
else | |
puts i.to_s |
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.bmbm do |x| | |
x.report('Break') do | |
1_000_000.times do | |
break | |
end | |
end |
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.bmbm do |x| | |
x.report("Stripping /n with String.strip") { 100_000.times {"filename.rb\n".strip} } | |
x.report("Stripping /n with String.chomp") { 100_000.times {"filename.rb\n".chomp} } | |
end |
NewerOlder