Class: Perfer::InputSizeJob

Inherits:
Job
  • Object
show all
Defined in:
lib/perfer/job/input_size_job.rb

Constant Summary collapse

DEFAULT_START =
1024
DEFAULT_GENERATOR =
lambda { |n| n * 2 }

Instance Attribute Summary collapse

Attributes inherited from Job

#metadata, #session, #title

Instance Method Summary collapse

Methods inherited from Job

#load_metadata, #minimal_time, #number_of_measurements, #results, #verbose

Constructor Details

#initialize(session, title, &block) ⇒ InputSizeJob

Returns a new instance of InputSizeJob.



8
9
10
11
12
13
14
# File 'lib/perfer/job/input_size_job.rb', line 8

def initialize(session, title, &block)
  super(session, title, &block)
  extra = @session.
  @start = (extra && extra.delete(:start)) || DEFAULT_START
  @generator = (extra && extra.delete(:generator)) || DEFAULT_GENERATOR
  
end

Instance Attribute Details

#last_measurement=(value) ⇒ Object (writeonly)

Sets the attribute last_measurement

Parameters:

  • value

    the value to set the attribute last_measurement to.



3
4
5
# File 'lib/perfer/job/input_size_job.rb', line 3

def last_measurement=(value)
  @last_measurement = value
end

Instance Method Details

#measure(n) ⇒ Object



16
17
18
19
20
# File 'lib/perfer/job/input_size_job.rb', line 16

def measure(n)
  GC.start
  @block.call(n)
  @last_measurement
end

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/perfer/job/input_size_job.rb', line 22

def run
  super
  n = @start
  # find an appropriate maximal n, acts as warm-up
  loop do
    time = measure(n)[:real]
    break if time > minimal_time
    n = @generator.call(n)
  end

  max = n
  n = @start
  loop do
    result = Result.new(@metadata)
    result[:input_size] = n
    number_of_measurements.times do
      result << measure(n)
    end
    @session.add_result(result)

    break if n == max
    n = @generator.call(n)
  end
end