Class: Benchmark

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

Class Method Summary collapse

Class Method Details

.bm(iterations = 1) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/volt/benchmark/benchmark.rb', line 3

def self.bm(iterations = 1)
  puts 'BM'

  times = []
  total_time = nil
  result = nil

  iterations.times do
    start_time = `Date.now()`
    result = yield
    end_time = `Date.now()`
    total_time = `end_time - start_time`
    times << total_time
  end

  if iterations == 1
    puts "TOTAL TIME: #{total_time}ms"
  else
    puts "Times: #{times.inspect}"
  end

  result
end