Class: PerfLab::Operator

Inherits:
Object
  • Object
show all
Defined in:
lib/perflab/operator.rb

Instance Method Summary collapse

Constructor Details

#initialize(existing:, improved:, equality:) ⇒ Operator

Returns a new instance of Operator.



3
4
5
6
7
# File 'lib/perflab/operator.rb', line 3

def initialize(existing:, improved:, equality:)
  @existing = existing
  @improved = improved
  @equality = equality
end

Instance Method Details

#bmbmObject



25
26
27
# File 'lib/perflab/operator.rb', line 25

def bmbm
  Benchmark.bmbm(@improved, @existing)
end

#bmbm_improvedObject



29
30
31
# File 'lib/perflab/operator.rb', line 29

def bmbm_improved
  Benchmark.bmbm(@improved)
end

#correct?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
58
# File 'lib/perflab/operator.rb', line 49

def correct?
  if @equality.present?
    result = @equality.call(@existing.call, @improved.call)
    raise ArgumentError, 'Equality must return a boolean' unless [TrueClass, FalseClass].include?(result.class)

    result
  else
    @existing.call == @improved.call
  end
end

#ipsObject



33
34
35
# File 'lib/perflab/operator.rb', line 33

def ips
  Benchmark.ips(@improved, @existing)
end

#ips_improvedObject



37
38
39
# File 'lib/perflab/operator.rb', line 37

def ips_improved
  Benchmark.ipsa(@improved)
end

#ipsaObject



41
42
43
# File 'lib/perflab/operator.rb', line 41

def ipsa
  Benchmark.ipsa(@improved, @existing)
end

#ipsa_improvedObject



45
46
47
# File 'lib/perflab/operator.rb', line 45

def ipsa_improved
  Benchmark.ipsa(@improved)
end

#profileObject



9
10
11
12
13
14
15
# File 'lib/perflab/operator.rb', line 9

def profile
  puts 'Rehearsal...'
  @improved.call

  puts 'Profiling...'
  Profiler.profile(@improved)
end

#profile_existingObject



17
18
19
20
21
22
23
# File 'lib/perflab/operator.rb', line 17

def profile_existing
  puts 'Rehearsal...'
  @existing.call

  puts 'Profiling...'
  Profiler.profile(@existing)
end