From 31521dc7973e2d5832469c75ac162b4fa7ab2fc3 Mon Sep 17 00:00:00 2001 From: Ryan Smith Date: Sun, 16 Jun 2013 17:47:12 -0700 Subject: [PATCH] make running bencmarks optional --- test/benchmark_test.rb | 62 ++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/test/benchmark_test.rb b/test/benchmark_test.rb index acf84d83..c379653f 100644 --- a/test/benchmark_test.rb +++ b/test/benchmark_test.rb @@ -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