Class: Tryouts::Drill::Sergeant::RBenchmark::ComparisonPartial

Inherits:
Object
  • Object
show all
Defined in:
lib/tryouts/drill/sergeant/rbenchmark.rb

Instance Method Summary collapse

Constructor Details

#initialize(block, options) ⇒ ComparisonPartial

Returns a new instance of ComparisonPartial.



21
22
23
24
# File 'lib/tryouts/drill/sergeant/rbenchmark.rb', line 21

def initialize( block, options )
  @block1 = block
  @options = options
end

Instance Method Details

#with(&block2) ⇒ Object Also known as: to



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tryouts/drill/sergeant/rbenchmark.rb', line 26

def with( &block2 )
  times1 = []
  times2 = []

  (1..@options[ :iterations ]).each do |iteration|
    if @options[ :verbose ]
      $stdout.print "."; $stdout.flush
    end

    times1 << ::Benchmark.realtime do
      @options[ :inner_iterations ].times do |i|
        @block1.call( iteration )
      end
    end
    times2 << ::Benchmark.realtime do
      @options[ :inner_iterations ].times do |i|
        block2.call( iteration )
      end
    end
  end

  r = RSRuby.instance
  wilcox_result = r.wilcox_test( times1, times2 )

  {
    :results1 => {
      :times => times1,
      :mean => r.mean( times1 ),
      :stddev => r.sd( times1 ),
    },
    :results2 => {
      :times => times2,
      :mean => r.mean( times2 ),
      :stddev => r.sd( times2 ),
    },
    :p => wilcox_result[ 'p.value' ],
    :W => wilcox_result[ 'statistic' ][ 'W' ],
    :significant => (
      wilcox_result[ 'p.value' ] < @options[ :required_significance ]
    ),
  }
end