Class: YARD::Bench::Marks

Inherits:
Object
  • Object
show all
Includes:
MonkeyPatches
Defined in:
lib/dsl/bm_dsl.rb

Overview

Class to be included for benchmarking DSL.

It contains ‘Hash` of the following structure:


Defined Under Namespace

Classes: Mark

Class Method Summary collapse

Class Method Details

.get(file, namespace, m) ⇒ Object

Returns benchmarks for the method given by spec (or the whole collection if none specified)



114
115
116
117
# File 'lib/dsl/bm_dsl.rb', line 114

def self.get file, namespace, m
  load "#{file}"
  self.∈! Object.const_get(namespace), m
end

.(clazz, m, iterations = 3) ⇒ Object

Measures the specified method of the class given

Parameters:

  • clazz (Class)

    the class to measure method for

  • m (Symbol)

    the method to measure

  • iterations (Fixnum) (defaults to: 3)

    an amount of iterations to do

Returns:

  • benchmarking total, normalized by STANDARD_TIME and 1_000_000 times



124
125
126
127
128
129
130
131
132
# File 'lib/dsl/bm_dsl.rb', line 124

def self. clazz, m, iterations = 3
  # Let’ calculate the applicable range
  deg = (1..10).each { |v|
    break v if Benchmark.measure { (10**v).times {clazz. m} }.total > 0.01
  }
  (deg...deg+iterations).to_a.map { |d| 10**d }.map { |e|
    { e => Benchmark.measure { e.times {clazz. m} }.total / STANDARD_TIME }
  }
end

.(clazz, m, iterations = 10) ⇒ Object

Measures the memory required for a method in KBytes. FIXME This is VERY inaccurate and lame.

Parameters:

  • clazz (Class)

    the class to measure method for

  • m (Symbol)

    the method to measure

  • iterations (Fixnum) (defaults to: 10)

    an amount of iterations to do

Returns:

  • an approximate amount of kilobytes



139
140
141
142
143
144
145
# File 'lib/dsl/bm_dsl.rb', line 139

def self. clazz, m, iterations = 10
  kb = `ps -o rss= -p #{$$}`.to_i
  iterations.times.map {
    clazz. m
    `ps -o rss= -p #{$$}`.to_i
  }.reduce(:+) / iterations - kb
end