Skip to content

Instantly share code, notes, and snippets.

Created Feb 6, 2011
Embed
What would you like to do?
gem 'minitest'
require 'minitest/autorun'
require 'minitest/benchmark'
class TestReddit < MiniTest::Unit::TestCase
def setup
@reddit = Reddit.new('IAAMA')
end
def test_hot_story
assert_equal "Convicted of DUI on a Bicycle. Ask me anything!", @reddit.hot
end
def bench_hot
assert_performance_constant 0.9999 do
@reddit.hot
end
end
def bench_hot2
assert_performance_linear 0.9999 do |n| # n is a range value
n.times do
@reddit.hot
end
end
end
end
------------------------------------------------------------
class Reddit
def hot
"Convicted of DUI on a Bicycle. Ask me anything!"
end
end
------------------------------------------------------------
output:
# Running benchmarks:
TestReddit 1 10 100 1000 10000
bench_hot 0.000039 0.000052 0.000032 0.000033 0.000032
bench_hot2 0.000046 0.000047 0.000088 0.000596 0.005650
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment