/usr/lib/ruby/vendor_ruby/benchmark/suite.rb is in ruby-benchmark-suite 1.0.0+git.20130122.5bded6-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | require 'benchmark'
module Benchmark
class Suite
@current = nil
def self.current
@current
end
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
class SimpleReport
def initialize
@start = nil
@end = nil
end
attr_reader :start, :end
end
def initialize
@report = nil
@reports = {}
@order = []
@quiet = false
@verbose = false
end
attr_reader :reports, :report
def quiet!
@quiet = true
end
def quiet?
@quiet
end
def warming(label, sec)
return unless @verbose
STDOUT.print "#{label.rjust(20)} warmup: #{sec}s"
end
def warmup_stats(time, cycles)
return unless @verbose
STDOUT.print " time=#{time}us, cycles=#{cycles}."
end
def running(label, sec)
return unless @verbose
STDOUT.puts " running: #{sec}s..."
end
def add_report(rep, location)
if @report
@report << rep
else
@report = [rep]
end
@report_location = location
end
def run(file)
start = Time.now
begin
load file
rescue Exception => e
STDOUT.puts "\nError in #{file}:"
if e.respond_to? :render
e.render
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
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
end
end
|