File: test_benchmark_ips.rb

package info (click to toggle)
ruby-benchmark-ips 1.2.0%2Bgit.20130609.e47e416-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 116 kB
  • ctags: 39
  • sloc: ruby: 308; makefile: 13
file content (26 lines) | stat: -rw-r--r-- 478 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require "test/unit"
require "benchmark/ips"
require "stringio"

class TestBenchmarkIPS < Test::Unit::TestCase
  def setup
    @old_stdout = $stdout
    $stdout = StringIO.new
  end

  def teardown
    $stdout = @old_stdout
  end

  def test_ips
    reports = Benchmark.ips(1,1) do |x|
      x.report("sleep") { sleep(0.25) }
    end

    rep = reports.first

    assert_equal "sleep", rep.label
    assert_equal 4, rep.iterations
    assert_in_delta 4.0, rep.ips, 0.2
  end
end