Class: Moon::Test::Benchmark::Suite

Inherits:
Object
  • Object
show all
Defined in:
lib/moon/packages/test/benchmark.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Suite


7
8
9
10
# File 'lib/moon/packages/test/benchmark.rb', line 7

def initialize(name)
  @name = name
  @list = []
end

Instance Attribute Details

#nameObject

Returns the value of attribute name


5
6
7
# File 'lib/moon/packages/test/benchmark.rb', line 5

def name
  @name
end

Instance Method Details

#benchmark(name = nil, &block) ⇒ Object Also known as: bm


12
13
14
# File 'lib/moon/packages/test/benchmark.rb', line 12

def benchmark(name = nil, &block)
  @list << [name, block]
end

#bmbm(name = nil, &block) ⇒ Object


18
19
20
21
# File 'lib/moon/packages/test/benchmark.rb', line 18

def bmbm(name = nil, &block)
  benchmark('~> priming: ' + name, &block)
  benchmark('~>    real: ' + name, &block)
end

#runObject


34
35
36
37
38
39
40
41
# File 'lib/moon/packages/test/benchmark.rb', line 34

def run
  puts 'Running Benchmark Suite: ' + name
  @list.each do |testcase|
    name, block = *testcase
    run_test(name, &block)
  end
  puts
end

#run_runObject


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/moon/packages/test/benchmark.rb', line 43

def run_run
  puts 'Running Benchmark Suite (bmbm): ' + name
  puts '~> priming suite'
  @list.each do |testcase|
    name, block = *testcase
    run_test(name, &block)
  end
  puts
  puts '~> real suite'
  @list.each do |testcase|
    name, block = *testcase
    run_test(name, &block)
  end
  puts
end

#run_test(name) ⇒ Object


23
24
25
26
27
28
29
30
31
32
# File 'lib/moon/packages/test/benchmark.rb', line 23

def run_test(name)
  error = -(Time.now - Time.now)
  time_then = Time.now
  yield
  time_now = Time.now
  diff = time_now - time_then
  diffwe = diff - error
  puts '    error: %0.6f    time: %0.6f    actual: %0.6f        %s' % [error, diffwe, diff, name]
  diff
end