Skip to content

Commit

Permalink
make running bencmarks optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Smith committed Jun 17, 2013
1 parent 80bdc9b commit 31521dc
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions test/benchmark_test.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
require File.expand_path("../helper.rb", __FILE__)

class BenchmarkTest < QCTest

def test_enqueue
n = 10_000
start = Time.now
n.times do
QC.enqueue("1.odd?", [])
end
assert_equal(n, QC.count)

elapsed = Time.now - start
assert_in_delta(4, elapsed, 1)
end

def test_dequeue
worker = QC::Worker.new
worker.running = true
n = 10_000
n.times do
QC.enqueue("1.odd?", [])
if ENV["QC_BENCHMARK"]
class BenchmarkTest < QCTest

def test_enqueue
n = 10_000
start = Time.now
n.times do
QC.enqueue("1.odd?", [])
end
assert_equal(n, QC.count)

elapsed = Time.now - start
assert_in_delta(4, elapsed, 1)
end
assert_equal(n, QC.count)

start = Time.now
n.times do
worker.work

def test_dequeue
worker = QC::Worker.new
worker.running = true
n = 10_000
n.times do
QC.enqueue("1.odd?", [])
end
assert_equal(n, QC.count)

start = Time.now
n.times do
worker.work
end
elapsed = Time.now - start

assert_equal(0, QC.count)
assert_in_delta(10, elapsed, 3)
end
elapsed = Time.now - start

assert_equal(0, QC.count)
assert_in_delta(10, elapsed, 3)

end

end

0 comments on commit 31521dc

Please sign in to comment.