Skip to content

Instantly share code, notes, and snippets.

@meatballhat
Created March 17, 2013 03:26
Show Gist options
  • Save meatballhat/5179425 to your computer and use it in GitHub Desktop.
Save meatballhat/5179425 to your computer and use it in GitHub Desktop.
Crappy benchmark thrown together while working on Topaz IO buffering
class Garbage
def write(n)
out.write(n.to_s)
out.print ' '
out.print 't'
out.print 'i'
out.print 'm'
out.print 'e'
out.print 's'
out.write('. ')
end
def out
@out ||= IO.new(2)
end
end
def main
multiplier = Float(ARGV.first || 1)
$stderr.puts "Using multiplier = #{multiplier}"
timings = []
2.times do |t|
start = Time.now
Integer(1_000_000 * multiplier).times do |n|
garbage_var = (2 ** 2) + n
garbage_writer = Garbage.new.write(garbage_var)
garbage_writer.to_s
end
timings << Time.now - start
end
$stderr.puts <<-EOF
WARMUP: #{timings.first}
DURATION: #{timings.last}
EOF
end
if $0 == __FILE__
main
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment