Skip to content

Instantly share code, notes, and snippets.

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
@JoshTGreenwood
JoshTGreenwood / bench.rb
Created November 21, 2012 00:14
Benchmark break vs. catch-throw vs. begin-rescue-end in ruby
require 'benchmark'
Benchmark.bmbm do |x|
x.report('Break') do
1_000_000.times do
break
end
end
@JoshTGreenwood
JoshTGreenwood / bench.rb
Created October 31, 2012 00:34
Benchmark strip vs. chomp in ruby
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