Module: Stud::Benchmark

Defined in:
lib/stud/benchmark.rb,
lib/stud/benchmark/rusage.rb

Defined Under Namespace

Modules: LibC Classes: RUsage, Results, TimeVal

Class Method Summary collapse

Class Method Details

.cputimed(seconds = 10, &block) ⇒ Object

def runtimed



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/stud/benchmark.rb', line 29

def self.cputimed(seconds=10, &block)
  timer = Metriks::Timer.new
  expiration = Time.now + seconds
  start_usage = Stud::Benchmark::RUsage.get
  while Time.now < expiration
    start = Stud::Benchmark::RUsage.get
    block.call
    finish = Stud::Benchmark::RUsage.get
    cputime = (finish.user + finish.system) - (start.user + start.system)
    timer.update(cputime)
  end # while not expired
  finish_usage = Stud::Benchmark::RUsage.get
  duration = (finish_usage.user + finish_usage.system) \
    - (start_usage.user + start_usage.system)
  return Results.new(timer, duration)
end

.run(iterations = 1, &block) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/stud/benchmark.rb', line 11

def self.run(iterations=1, &block)
  timer = Metriks::Timer.new
  start = Time.now
  iterations.times { timer.time(&block) }
  duration = Time.now - start
  return Results.new(timer, duration)
end

.runtimed(seconds = 10, &block) ⇒ Object

def run



19
20
21
22
23
24
25
26
27
# File 'lib/stud/benchmark.rb', line 19

def self.runtimed(seconds=10, &block)
  timer = Metriks::Timer.new
  expiration = Time.now + seconds

  start = Time.now
  timer.time(&block) while Time.now < expiration
  duration = Time.now - start
  return Results.new(timer, duration)
end