Class: Benchmark

Inherits:
Object show all
Defined in:
lib/project/benchmark.rb

Class Method Summary collapse

Class Method Details

.decimal_formatterObject



3
4
5
# File 'lib/project/benchmark.rb', line 3

def decimal_formatter
  @_decimal_formatter ||= Potion::DecimalFormat.new("#,###,###")
end

.run_single(setup_desc, code_desc, iterations, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/project/benchmark.rb', line 11

def run_single(setup_desc, code_desc, iterations, &block)
  @total_run ||= 0
  start_time = Time.milliseconds_since_epoch
  iterations.times do
    @total_run += 1
    block.call
    #mp "[#{@total_run}]"
  end
  end_time = Time.milliseconds_since_epoch

  total_time = end_time - start_time
  per_item = total_time / iterations.to_f
  out =  "\nBenchmark  Started at: #{decimal_formatter.format(start_time)}"
  out << "\n  Iterations: #{decimal_formatter.format(iterations)}"
  out << "\n  Setup: #{setup_desc}\n  Code: #{code_desc}"
  out << "\n  Total milliseconds: #{decimal_formatter.format(total_time)}"
  out << "\n  Milliseconds per iteration: #{per_item}"
  out << "\n  RMQ allocations: #{$rmq_initialized.to_s}"
  mp out
  Potion::System.gc
  out
end

.total_runObject



7
8
9
# File 'lib/project/benchmark.rb', line 7

def total_run
  @total_run
end