public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Search Repo:
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Hongli Lai (Phusion) (author)
Thu May 01 12:13:06 -0700 2008
commit  53301de464b323d364723854d3a8d293ab8327d6
tree    23e53e1e40d0fea9ecd6312dca292b3e7f2f5cb8
parent  3f5fb12ba8240018c6210a42d2550d21a3cd6497
passenger / lib / passenger / simple_benchmarking.rb
100644 45 lines (42 sloc) 1.356 kb
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
# Phusion Passenger - http://www.modrails.com/
# Copyright (C) 2008 Phusion
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
class Object # :nodoc:
  @@benchmark_results = {}
 
  def b!(name)
    time1 = Time.now
    begin
      yield
    ensure
      time2 = Time.now
      @@benchmark_results[name] = 0 unless @@benchmark_results.has_key?(name)
      @@benchmark_results[name] += time2 - time1
    end
  end
 
  def benchmark_report(main = nil)
    total = 0
    if main.nil?
      @@benchmark_results.each_value do |time|
        total += time
      end
    else
      total = @@benchmark_results[main]
    end
    @@benchmark_results.each_pair do |name, time|
      printf "%-12s: %.4f (%.2f%%)\n", name, time, time / total * 100
    end
    printf "-- Total: %.4f\n", total
  end
end