In Files

Parent

Files

Bullshit::Histogram

A histogram gives an overview of measurement time values.

Attributes

bins[R]

Number of bins for this Histogram.

Public Class Methods

new(analysis, bins) click to toggle source

Create a Histogram for clock using the measurements for time.

# File lib/bullshit.rb, line 550
    def initialize(analysis, bins)
      @analysis = analysis
      @bins = bins
      @result = compute
    end

Public Instance Methods

display(output = $stdout, width = 50) click to toggle source

Display this histogram to output, width is the parameter for prepare_display

# File lib/bullshit.rb, line 566
    def display(output = $stdout, width = 50)
      d = prepare_display(width)
      for l, bar, r in d
        output << "%11.5f -|%s\n" % [ (l + r) / 2.0, "*" * bar ]
      end
      self
    end
to_a() click to toggle source

Return the computed histogram as an array of arrays.

# File lib/bullshit.rb, line 560
    def to_a
      @result
    end

Private Instance Methods

compute() click to toggle source

Computes the histogram and returns it as an array of tuples (l, c, r).

# File lib/bullshit.rb, line 587
    def compute
      @analysis.measurements.empty? and return []
      last_r = -Infinity
      min = @analysis.min
      max = @analysis.max
      step = (max - min) / bins.to_f
      Array.new(bins) do |i|
        l = min + i  * step
        r = min + (i + 1) * step
        c = 0
        @analysis.measurements.each do |x|
          x > last_r and (x <= r || i == bins - 1) and c += 1
        end
        last_r = r
        [ l, c, r ]
      end
    end
prepare_display(width) click to toggle source

Returns an array of tuples (l, c, r) where l is the left bin edge, c the width-normalized frequence count value, and r the right bin edge. width is usually an integer number representing the width of a histogram bar.

# File lib/bullshit.rb, line 580
    def prepare_display(width)
      r = @result.reverse
      factor = width.to_f / (r.transpose[1].max)
      r.map { |l, c, r| [ l, (c * factor).round, r ] }
    end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.