In Files

Parent

Files

Bullshit::Clock

A Clock instance is used to take measurements while benchmarking.

Constants

TIMES
(Not documented)
ALL_COLUMNS
(Not documented)
TIMES_MAX
(Not documented)

Attributes

bc_method[R]

Returns the benchmark method for this Clock instance.

repeat[RW]

Number of repetitions this clock has measured.

time[R]

Last time object used for real time measurement.

slopes[R]

Return all the slopes of linear regressions computed during data truncation phase.

Public Class Methods

new(bc_method) click to toggle source

Returns a Clock instance for CaseMethod instance bc_method.

# File lib/bullshit.rb, line 213
    def initialize(bc_method)
      @bc_method = bc_method
      @times = Hash.new { |h, k| h[k] = [] }
      @repeat = 0
      @scatter = 0
    end
repeat(bc_method) click to toggle source

Use a Clock instance to measure the time necessary to do bc_method.case.iterations repetitions of bc_method.

# File lib/bullshit.rb, line 222
    def self.repeat(bc_method)
      clock = new(bc_method)
      bs = clock.case.batch_size.abs
      bs = 1 if !bs or bs < 0
      clock.case.iterations.times do
        bc_method.before_run
        $DEBUG and warn "Calling #{bc_method.name}."
        clock.inc_scatter
        clock.measure do
          bs.times { yield }
        end
        bc_method.after_run
      end
      clock
    end
scale_range(bc_method) click to toggle source

Iterate over the range of the RangeCase instance of this bc_method and take measurements (including scattering).

# File lib/bullshit.rb, line 265
    def self.scale_range(bc_method)
      clock = new(bc_method)
      my_case = clock.case
      bs = my_case.batch_size.abs
      bs = 1 if !bs or bs < 0
      for a in my_case.range
        begin
          my_case.args = (a.dup rescue a).freeze
          clock.inc_scatter
          my_case.scatter.times do
            bc_method.before_run
            $DEBUG and warn "Calling #{bc_method.name}."
            clock.measure do
              bs.times { yield }
            end
            bc_method.after_run
          end
        ensure
          my_case.args = nil
        end
      end
      clock
    end
time(bc_method) click to toggle source

Use a Clock instance to measure how many repetitions of bc_method can be done in bc_method.case.duration seconds (a float value). If the bc_method.case.batch_size is >1 duration is multiplied by batch_size because the measured times are averaged by batch_size.

# File lib/bullshit.rb, line 242
    def self.time(bc_method)
      clock = new(bc_method)
      duration = clock.case.duration.abs
      if bs = clock.case.batch_size and bs > 1
        duration *= bs
      end
      until_at = Time.now + duration
      bs = clock.case.batch_size.abs
      bs = 1 if !bs or bs < 0
      begin 
        bc_method.before_run
        $DEBUG and warn "Calling #{bc_method.name}."
        clock.inc_scatter
        clock.measure do
          bs.times { yield }
        end
        bc_method.after_run
      end until clock.time > until_at
      clock
    end
times() click to toggle source

The times which should be displayed in the output.

# File lib/bullshit.rb, line 486
    def self.times
      TIMES.map { |t| t.to_s }
    end
to_a() click to toggle source

Return column names in relation to Clock#to_a method.

# File lib/bullshit.rb, line 337
    def self.to_a
      %w[ #scatter ] + TIMES + %w[ repeat ]
    end

Public Instance Methods

<<(times) click to toggle source

Add the array times to this clock’s time measurements. times consists of the time measurements in float values in order of TIMES.

# File lib/bullshit.rb, line 309
    def <<(times)
      r = times.shift
      @repeat += 1 if @times[:repeat].last != r
      @times[:repeat] << r
      TIMES.zip(times) { |t, time| @times[t] << time.to_f }
      self
    end
analysis() click to toggle source

Returns a Hash of Analysis object for all of TIMES’s time keys.

# File lib/bullshit.rb, line 318
    def analysis
      @analysis ||= Hash.new do |h, time|
        time = time.to_sym
        times = @times[time]
        h[time] = Analysis.new(times)
      end
    end
arithmetic_mean(time) click to toggle source

Returns the arithmetic mean of time.

# File lib/bullshit.rb, line 469
    def arithmetic_mean(time)
      analysis[time.to_sym].mean
    end
Also aliased as: mean
autocorrelation(time) click to toggle source

Return the array of autocorrelation values for time.

# File lib/bullshit.rb, line 496
    def autocorrelation(time)
      analysis[time.to_sym].autocorrelation
    end
autocorrelation_plot(time) click to toggle source

Returns the arrays for the autocorrelation plot, the first array for the numbers of lag measured, the second for the autocorrelation value.

# File lib/bullshit.rb, line 502
    def autocorrelation_plot(time)
      r = autocorrelation time
      start = @times[:repeat].first
      ende = (start + r.size)
      (start...ende).to_a.zip(r)
    end
call_time_mean() click to toggle source

Seconds per call (mean)

# File lib/bullshit.rb, line 443
    def call_time_mean
      mean(self.case.compare_time)
    end
call_time_median() click to toggle source

Seconds per call (median)

# File lib/bullshit.rb, line 459
    def call_time_median
      median(self.case.compare_time)
    end
calls(call_time_type) click to toggle source

Calls per second of the call_time_type, e. g. :call_time_mean or :call_time_median.

# File lib/bullshit.rb, line 449
    def calls(call_time_type)
      __send__(call_time_type) ** -1
    end
calls_mean() click to toggle source

Calls per second (mean)

# File lib/bullshit.rb, line 454
    def calls_mean
      call_time_mean ** -1
    end
calls_median() click to toggle source

Calls per second (median)

# File lib/bullshit.rb, line 464
    def calls_median
      call_time_median ** -1
    end
case() click to toggle source

The benchmark case class this clock belongs to (via bc_method).

# File lib/bullshit.rb, line 290
    def case
      @bc_method.case.class
    end
cover?(other) click to toggle source

Return true, if other’s mean value is indistinguishable from this object’s mean after filtering out the noise from the measurements with a Welch’s t-Test. This mean’s that differences in the mean of both clocks might not inidicate a real performance difference and may be caused by chance.

# File lib/bullshit.rb, line 331
    def cover?(other)
      time = self.case.compare_time.to_sym
      analysis[time].cover?(other.analysis[time], self.case.covering.alpha_level.abs)
    end
detect_autocorrelation(time) click to toggle source

Returns the q value for the Ljung-Box statistic of this time’s analysis.detect_autocorrelation method.

# File lib/bullshit.rb, line 419
    def detect_autocorrelation(time)
      analysis[time.to_sym].detect_autocorrelation(
        self.case.autocorrelation.max_lags.to_i,
        self.case.autocorrelation.alpha_level.abs)
    end
detect_outliers(time) click to toggle source

Return a result hash with the number of :very_low, :low, :high, and :very_high outliers, determined by the box plotting algorithm run with :median and :iqr parameters. If no outliers were found or the iqr is less than epsilon, nil is returned.

# File lib/bullshit.rb, line 429
    def detect_outliers(time)
      analysis[time.to_sym].detect_outliers(self.case.outliers_factor.abs)
    end
file_path(*args) click to toggle source

Return the result of CaseMethod#file_path for this clock’s bc_method.

# File lib/bullshit.rb, line 510
    def file_path(*args)
      @bc_method.file_path(*args)
    end
find_truncation_offset() click to toggle source

Find an offset from the start of the measurements in this clock to truncate the initial data until a stable state has been reached and return it as an integer.

# File lib/bullshit.rb, line 529
    def find_truncation_offset
      truncation = self.case.truncate_data
      slope_angle = self.case.truncate_data.slope_angle.abs
      time = self.case.compare_time.to_sym
      ms = analysis[time].measurements.reverse
      offset = ms.size - 1
      @slopes = []
      ModuleFunctions.array_window(ms, truncation.window_size) do |data|
        lr = LinearRegression.new(data)
        a = lr.a
        @slopes << [ offset, a ]
        a.abs > slope_angle and break
        offset -= 1
      end
      offset < 0 ? 0 : offset
    end
geometric_mean(time) click to toggle source

Returns the geometric mean of time.

# File lib/bullshit.rb, line 481
    def geometric_mean(time)
      analysis[time.to_sym].geometric_mean
    end
harmonic_mean(time) click to toggle source

Returns the harmonic mean of time.

# File lib/bullshit.rb, line 476
    def harmonic_mean(time)
      analysis[time.to_sym].harmonic_mean
    end
histogram(time) click to toggle source

Return the Histogram for the time values.

# File lib/bullshit.rb, line 491
    def histogram(time)
      analysis[time.to_sym].histogram(self.case.histogram.bins)
    end
inc_scatter() click to toggle source

Increment scatter counter by one.

# File lib/bullshit.rb, line 363
    def inc_scatter
      @scatter += 1
    end
max(time) click to toggle source

Returns the maximum for the time (one of TIMES’ symbols).

# File lib/bullshit.rb, line 403
    def max(time)
      analysis[time.to_sym].max
    end
mean(time) click to toggle source

Alias for arithmetic_mean

measure() click to toggle source

Take a single measurement. This method should be called with the code to benchmark in a block.

# File lib/bullshit.rb, line 369
    def measure
      before = take_time
      yield
      after = take_time
      @repeat += 1
      @times[:repeat] << @repeat
      @times[:scatter] << @scatter
      bs = self.case.batch_size.abs
      if bs and bs > 1
        TIMES.each_with_index { |t, i| @times[t] << (after[i] - before[i]) / bs }
      else
        TIMES.each_with_index { |t, i| @times[t] << after[i] - before[i] }
      end
      @analysis = nil
    end
median(time) click to toggle source

Returns the median of the time values (one of TIMES’ symbols).

# File lib/bullshit.rb, line 408
    def median(time)
      analysis[time.to_sym].median
    end
min(time) click to toggle source

Returns the minimum for the time (one of TIMES’ symbols).

# File lib/bullshit.rb, line 398
    def min(time)
      analysis[time.to_sym].min
    end
percentile(time, p = 50) click to toggle source

Returns the p-percentile of the time values (one of TIMES’ symbols).

# File lib/bullshit.rb, line 413
    def percentile(time, p = 50)
      analysis[time.to_sym].percentile p
    end
sample_standard_deviation(time) click to toggle source

Returns the sample standard deviation for the time (one of TIMES’ symbols).

# File lib/bullshit.rb, line 387
    def sample_standard_deviation(time)
      analysis[time.to_sym].sample_standard_deviation
    end
sample_standard_deviation_percentage(time) click to toggle source

Returns the sample standard deviation for the time (one of TIMES’ symbols) in percentage of its arithmetic mean.

# File lib/bullshit.rb, line 393
    def sample_standard_deviation_percentage(time)
      analysis[time.to_sym].sample_standard_deviation_percentage
    end
sum(time) click to toggle source

Returns the sum of measurement times for time.

# File lib/bullshit.rb, line 438
    def sum(time)
      __send__ time
    end
take_time() click to toggle source

Takes the times an returns an array, consisting of the times in the order of enumerated in the TIMES constant.

# File lib/bullshit.rb, line 354
    def take_time
      @time, times = Time.now, Process.times
      user_time = times.utime + times.cutime    # user time of this process and its children
      system_time = times.stime + times.cstime  # system time of this process and its children
      total_time = user_time + system_time      # total time of this process and its children
      [ @time.to_f, total_time, user_time, system_time ]
    end
to_a() click to toggle source

Returns the measurements as an array of arrays.

# File lib/bullshit.rb, line 342
    def to_a
      if @repeat >= 1
        (::Bullshit::Clock::ALL_COLUMNS).map do |t|
          analysis[t].measurements
        end.transpose
      else
        []
      end
    end
truncate_data(offset) click to toggle source

Truncate the measurements stored in this clock starting from the integer offset.

# File lib/bullshit.rb, line 516
    def truncate_data(offset)
      for t in ALL_COLUMNS
        times = @times[t]
        @times[t] = @times[t][offset, times.size]
        @repeat = @times[t].size
      end
      @analysis = nil
      self
    end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.