Class: Benchmark::Suite
- Inherits:
-
Object
- Object
- Benchmark::Suite
- Defined in:
- lib/benchmark/suite.rb
Defined Under Namespace
Classes: SimpleReport
Instance Attribute Summary collapse
-
#reports ⇒ Object
readonly
Returns the value of attribute reports.
Class Method Summary collapse
Instance Method Summary collapse
- #add_report(rep, location) ⇒ Object
- #display ⇒ Object
-
#initialize ⇒ Suite
constructor
A new instance of Suite.
- #quiet! ⇒ Object
- #quiet? ⇒ Boolean
- #run(file) ⇒ Object
- #running(label, sec) ⇒ Object
- #warming(label, sec) ⇒ Object
- #warmup_stats(time, cycles) ⇒ Object
Constructor Details
#initialize ⇒ Suite
Returns a new instance of Suite.
35 36 37 38 39 40 |
# File 'lib/benchmark/suite.rb', line 35 def initialize @report = nil @reports = {} @order = [] @quiet = false end |
Instance Attribute Details
#reports ⇒ Object (readonly)
Returns the value of attribute reports.
42 43 44 |
# File 'lib/benchmark/suite.rb', line 42 def reports @reports end |
Class Method Details
.create ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/benchmark/suite.rb', line 9 def self.create if block_given? old = @current begin s = new @current = s yield s return s ensure @current = old end else @current = new end end |
.current ⇒ Object
5 6 7 |
# File 'lib/benchmark/suite.rb', line 5 def self.current @current end |
Instance Method Details
#add_report(rep, location) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/benchmark/suite.rb', line 67 def add_report(rep, location) if @report @report << rep else @report = [rep] end @report_location = location end |
#display ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/benchmark/suite.rb', line 104 def display if @report file = @report_location ? @report_location.split(":").first : "<unknown.rb>" @order << file @reports[file] = [@report] end @order.each do |file| STDOUT.puts "#{file}:" reports = @reports[file] if reports.empty? STDOUT.puts " NO REPORTS FOUND" else reports.each do |rep| STDOUT.puts " #{rep}" end end end end |
#quiet! ⇒ Object
44 45 46 |
# File 'lib/benchmark/suite.rb', line 44 def quiet! @quiet = true end |
#quiet? ⇒ Boolean
48 49 50 |
# File 'lib/benchmark/suite.rb', line 48 def quiet? @quiet end |
#run(file) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/benchmark/suite.rb', line 77 def run(file) start = Time.now begin load file rescue Exception => e STDOUT.puts "\nError in #{file}:" if e.respond_to? :render e.render(STDERR) else STDOUT.puts e.backtrace end return end fin = Time.now if @report @reports[file] = @report @report = nil else @reports[file] = SimpleReport.new(start, fin) end @order << file end |
#running(label, sec) ⇒ Object
62 63 64 65 |
# File 'lib/benchmark/suite.rb', line 62 def running(label, sec) return unless @verbose STDOUT.puts " running: #{sec}s..." end |
#warming(label, sec) ⇒ Object
52 53 54 55 |
# File 'lib/benchmark/suite.rb', line 52 def warming(label, sec) return unless @verbose STDOUT.print "#{label.rjust(20)} warmup: #{sec}s" end |
#warmup_stats(time, cycles) ⇒ Object
57 58 59 60 |
# File 'lib/benchmark/suite.rb', line 57 def warmup_stats(time, cycles) return unless @verbose STDOUT.print " time=#{time}us, cycles=#{cycles}." end |