Module: BenchmarkX

Includes:
Benchmark
Defined in:
lib/benchmarkx.rb

Defined Under Namespace

Classes: Report

Constant Summary collapse

VERSION =
"001"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.benchmark(caption = "", label_width = nil, fmtstr = nil, *labels) ⇒ Object

Same as Benchmark.benchmark.

Raises:

  • (ArgumentError)


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

def benchmark(caption = "", label_width = nil, fmtstr = nil, *labels)
  # copied from benchmark.rb
  sync = STDOUT.sync
  STDOUT.sync = true
  label_width ||= 0
  fmtstr ||= FMTSTR
  raise ArgumentError, "no block" unless iterator?
  print caption

  # modified
  report = Report.new(label_width, fmtstr)
  results = yield(report)

  # copied from benchmark.rb and modified
  Array === results and results.grep(Tms).each {|t|
    label = labels.shift
    print((label || t.label || "").ljust(label_width), t.format(fmtstr))
    report.record(label, t)
  }
  STDOUT.sync = sync

  # new
  report.render
end

.bmObject

.bmbm(width = 0) {|job| ... } ⇒ Object

Same as Benchmark.bmbm

Yields:

  • (job)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/benchmarkx.rb', line 40

def bmbm(width = 0, &blk)
  # copied from benchmark.rb
  job = Job.new(width)
  yield(job)
  width = job.width
  sync = STDOUT.sync
  STDOUT.sync = true

  # copied from benchmark.rb
  # rehearsal
  print "Rehearsal "
  puts '-'*(width+CAPTION.length - "Rehearsal ".length)
  list = []
  rehearsal = Report.new # appended
  job.list.each{|label,item|
    print(label.ljust(width))
    res = Benchmark::measure(&item)
    print res.format()
    list.push res

    # new
    rehearsal.record(label, res)
  }
  sum = Tms.new; list.each{|i| sum += i}
  ets = sum.format("total: %tsec")
  printf("%s %s\n\n",
         "-"*(width+CAPTION.length-ets.length-1), ets)

  # new
  rehearsal.filename = "rehearsal-" + rehearsal.filename
  rehearsal.gruff.title = rehearsal.gruff.title.to_s + "(Rehearsal)"
  rehearsal.render

  # copied from benchmark.rb
  # take
  print ' '*width, CAPTION
  list = []
  ary = []
  report = Report.new # appended
  job.list.each{|label,item|
    GC::start
    print label.ljust(width)
    res = Benchmark::measure(&item)
    print res.format()
    ary.push res
    list.push [label, res]

    # new
    report.record(label, res)
  }

  # new
  report.render

  # copied from benchmark.rb
  STDOUT.sync = sync
  ary
end

.measureObject

.realtimeObject

Instance Method Details

#benchmark_origObject



9
# File 'lib/benchmarkx.rb', line 9

alias :benchmark_orig :benchmark

#bmbm_origObject



37
# File 'lib/benchmarkx.rb', line 37

alias :bmbm_orig :bmbm