Current Path: > > opt > > alt > ruby19 > lib64 > > ruby > 1.9.1
Operation : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64 Software : Apache Server IP : 162.0.232.56 | Your IP: 216.73.216.111 Domains : 1034 Domain(s) Permission : [ 0755 ]
Name | Type | Size | Last Modified | Actions |
---|---|---|---|---|
cgi | Directory | - | - | |
date | Directory | - | - | |
digest | Directory | - | - | |
dl | Directory | - | - | |
drb | Directory | - | - | |
fiddle | Directory | - | - | |
irb | Directory | - | - | |
json | Directory | - | - | |
matrix | Directory | - | - | |
net | Directory | - | - | |
openssl | Directory | - | - | |
optparse | Directory | - | - | |
psych | Directory | - | - | |
racc | Directory | - | - | |
rake | Directory | - | - | |
rbconfig | Directory | - | - | |
rdoc | Directory | - | - | |
rexml | Directory | - | - | |
rinda | Directory | - | - | |
ripper | Directory | - | - | |
rss | Directory | - | - | |
rubygems | Directory | - | - | |
shell | Directory | - | - | |
syck | Directory | - | - | |
test | Directory | - | - | |
uri | Directory | - | - | |
webrick | Directory | - | - | |
x86_64-linux | Directory | - | - | |
xmlrpc | Directory | - | - | |
yaml | Directory | - | - | |
English.rb | File | 5722 bytes | October 02 2009 10:45:39. | |
abbrev.rb | File | 2627 bytes | May 18 2011 21:19:18. | |
base64.rb | File | 2694 bytes | October 02 2009 10:45:39. | |
benchmark.rb | File | 18431 bytes | June 28 2011 06:09:46. | |
cgi.rb | File | 9519 bytes | May 16 2011 21:21:35. | |
cmath.rb | File | 7396 bytes | July 30 2011 14:53:14. | |
complex.rb | File | 380 bytes | August 16 2009 15:34:35. | |
csv.rb | File | 84647 bytes | July 21 2011 21:40:21. | |
date.rb | File | 946 bytes | May 21 2011 12:25:03. | |
debug.rb | File | 23785 bytes | June 28 2011 11:45:50. | |
delegate.rb | File | 9972 bytes | July 27 2011 19:56:28. | |
digest.rb | File | 2298 bytes | May 16 2011 20:52:55. | |
dl.rb | File | 176 bytes | June 12 2010 15:28:47. | |
drb.rb | File | 19 bytes | October 02 2009 10:45:39. | |
e2mmap.rb | File | 3896 bytes | May 19 2011 00:07:25. | |
erb.rb | File | 26334 bytes | December 13 2012 05:24:26. | |
expect.rb | File | 1364 bytes | August 26 2011 23:54:49. | |
fiddle.rb | File | 928 bytes | August 16 2011 00:51:58. | |
fileutils.rb | File | 46411 bytes | February 25 2012 08:11:07. | |
find.rb | File | 2080 bytes | May 18 2011 21:19:18. | |
forwardable.rb | File | 7823 bytes | May 22 2011 02:14:57. | |
getoptlong.rb | File | 15749 bytes | May 19 2011 00:07:25. | |
gserver.rb | File | 9044 bytes | October 31 2013 14:40:55. | |
ipaddr.rb | File | 25520 bytes | April 11 2013 02:31:05. | |
irb.rb | File | 8538 bytes | May 19 2011 00:07:25. | |
json.rb | File | 1779 bytes | August 30 2011 02:25:32. | |
kconv.rb | File | 5875 bytes | December 07 2010 11:47:39. | |
logger.rb | File | 21346 bytes | May 19 2011 00:07:25. | |
mathn.rb | File | 6681 bytes | August 26 2011 23:54:49. | |
matrix.rb | File | 48790 bytes | July 09 2011 19:11:06. | |
mkmf.rb | File | 70553 bytes | February 06 2014 05:20:52. | |
monitor.rb | File | 7102 bytes | June 17 2011 22:33:54. | |
mutex_m.rb | File | 1650 bytes | May 19 2011 00:07:25. | |
observer.rb | File | 5823 bytes | May 16 2011 21:53:12. | |
open-uri.rb | File | 26464 bytes | February 24 2014 03:43:27. | |
open3.rb | File | 21138 bytes | May 18 2011 21:19:18. | |
openssl.rb | File | 547 bytes | July 25 2011 06:38:44. | |
optparse.rb | File | 52356 bytes | February 14 2014 04:52:03. | |
ostruct.rb | File | 6650 bytes | February 24 2012 14:49:51. | |
pathname.rb | File | 14549 bytes | August 26 2011 23:54:49. | |
pp.rb | File | 13630 bytes | August 01 2010 14:09:40. | |
prettyprint.rb | File | 9859 bytes | August 02 2011 15:25:59. | |
prime.rb | File | 14312 bytes | June 01 2011 00:21:46. | |
profile.rb | File | 205 bytes | October 02 2009 10:45:39. | |
profiler.rb | File | 1626 bytes | October 02 2009 10:45:39. | |
pstore.rb | File | 16187 bytes | October 10 2011 23:14:17. | |
psych.rb | File | 10055 bytes | August 07 2012 20:50:05. | |
rake.rb | File | 2066 bytes | June 29 2011 03:09:34. | |
rational.rb | File | 308 bytes | September 24 2009 00:42:23. | |
rdoc.rb | File | 4390 bytes | February 06 2013 08:00:49. | |
resolv-replace.rb | File | 1782 bytes | October 29 2010 22:02:39. | |
resolv.rb | File | 61352 bytes | February 14 2014 06:56:54. | |
ripper.rb | File | 91 bytes | October 02 2009 10:45:39. | |
rss.rb | File | 2909 bytes | May 11 2011 10:22:16. | |
rubygems.rb | File | 34953 bytes | December 22 2013 04:38:28. | |
scanf.rb | File | 24094 bytes | May 20 2011 12:22:26. | |
securerandom.rb | File | 8662 bytes | May 07 2012 11:25:45. | |
set.rb | File | 30625 bytes | February 10 2012 08:28:48. | |
shell.rb | File | 6046 bytes | May 19 2011 00:07:25. | |
shellwords.rb | File | 3970 bytes | February 12 2012 07:51:05. | |
singleton.rb | File | 4114 bytes | May 18 2011 14:09:38. | |
socket.rb | File | 23777 bytes | January 30 2014 12:04:22. | |
syck.rb | File | 14247 bytes | July 19 2010 04:54:06. | |
sync.rb | File | 7039 bytes | June 29 2011 03:09:34. | |
tempfile.rb | File | 10669 bytes | October 31 2013 14:44:40. | |
thread.rb | File | 6747 bytes | February 14 2014 03:48:42. | |
thwait.rb | File | 3457 bytes | June 29 2011 03:09:34. | |
time.rb | File | 17440 bytes | October 31 2013 14:06:50. | |
timeout.rb | File | 3335 bytes | April 02 2013 04:09:07. | |
tmpdir.rb | File | 3812 bytes | May 18 2011 21:19:18. | |
tracer.rb | File | 6788 bytes | June 29 2011 13:19:59. | |
tsort.rb | File | 6958 bytes | March 06 2009 04:23:05. | |
ubygems.rb | File | 268 bytes | October 02 2009 10:45:39. | |
un.rb | File | 8523 bytes | May 19 2011 00:07:25. | |
uri.rb | File | 3144 bytes | May 13 2011 20:03:21. | |
weakref.rb | File | 2347 bytes | August 26 2011 23:54:49. | |
webrick.rb | File | 6964 bytes | May 10 2011 23:37:43. | |
yaml.rb | File | 2641 bytes | May 29 2013 12:00:57. |
#-- # benchmark.rb - a performance benchmarking library # # $Id: benchmark.rb 32269 2011-06-28 06:09:46Z naruse $ # # Created by Gotoken (gotoken@notwork.org). # # Documentation by Gotoken (original RD), Lyle Johnson (RDoc conversion), and # Gavin Sinclair (editing). #++ # # == Overview # # The Benchmark module provides methods for benchmarking Ruby code, giving # detailed reports on the time taken for each task. # # The Benchmark module provides methods to measure and report the time # used to execute Ruby code. # # * Measure the time to construct the string given by the expression # <tt>"a"*1_000_000</tt>: # # require 'benchmark' # # puts Benchmark.measure { "a"*1_000_000 } # # On my machine (FreeBSD 3.2 on P5, 100MHz) this generates: # # 1.166667 0.050000 1.216667 ( 0.571355) # # This report shows the user CPU time, system CPU time, the sum of # the user and system CPU times, and the elapsed real time. The unit # of time is seconds. # # * Do some experiments sequentially using the #bm method: # # require 'benchmark' # # n = 50000 # Benchmark.bm do |x| # x.report { for i in 1..n; a = "1"; end } # x.report { n.times do ; a = "1"; end } # x.report { 1.upto(n) do ; a = "1"; end } # end # # The result: # # user system total real # 1.033333 0.016667 1.016667 ( 0.492106) # 1.483333 0.000000 1.483333 ( 0.694605) # 1.516667 0.000000 1.516667 ( 0.711077) # # * Continuing the previous example, put a label in each report: # # require 'benchmark' # # n = 50000 # Benchmark.bm(7) do |x| # x.report("for:") { for i in 1..n; a = "1"; end } # x.report("times:") { n.times do ; a = "1"; end } # x.report("upto:") { 1.upto(n) do ; a = "1"; end } # end # # The result: # # user system total real # for: 1.050000 0.000000 1.050000 ( 0.503462) # times: 1.533333 0.016667 1.550000 ( 0.735473) # upto: 1.500000 0.016667 1.516667 ( 0.711239) # # # * The times for some benchmarks depend on the order in which items # are run. These differences are due to the cost of memory # allocation and garbage collection. To avoid these discrepancies, # the #bmbm method is provided. For example, to compare ways to # sort an array of floats: # # require 'benchmark' # # array = (1..1000000).map { rand } # # Benchmark.bmbm do |x| # x.report("sort!") { array.dup.sort! } # x.report("sort") { array.dup.sort } # end # # The result: # # Rehearsal ----------------------------------------- # sort! 11.928000 0.010000 11.938000 ( 12.756000) # sort 13.048000 0.020000 13.068000 ( 13.857000) # ------------------------------- total: 25.006000sec # # user system total real # sort! 12.959000 0.010000 12.969000 ( 13.793000) # sort 12.007000 0.000000 12.007000 ( 12.791000) # # # * Report statistics of sequential experiments with unique labels, # using the #benchmark method: # # require 'benchmark' # include Benchmark # we need the CAPTION and FORMAT constants # # n = 50000 # Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x| # tf = x.report("for:") { for i in 1..n; a = "1"; end } # tt = x.report("times:") { n.times do ; a = "1"; end } # tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end } # [tf+tt+tu, (tf+tt+tu)/3] # end # # The result: # # user system total real # for: 1.016667 0.016667 1.033333 ( 0.485749) # times: 1.450000 0.016667 1.466667 ( 0.681367) # upto: 1.533333 0.000000 1.533333 ( 0.722166) # >total: 4.000000 0.033333 4.033333 ( 1.889282) # >avg: 1.333333 0.011111 1.344444 ( 0.629761) module Benchmark BENCHMARK_VERSION = "2002-04-25" #:nodoc" # Invokes the block with a <tt>Benchmark::Report</tt> object, which # may be used to collect and report on the results of individual # benchmark tests. Reserves <i>label_width</i> leading spaces for # labels on each line. Prints _caption_ at the top of the # report, and uses _format_ to format each line. # Returns an array of Benchmark::Tms objects. # # If the block returns an array of # <tt>Benchmark::Tms</tt> objects, these will be used to format # additional lines of output. If _label_ parameters are # given, these are used to label these extra lines. # # _Note_: Other methods provide a simpler interface to this one, and are # suitable for nearly all benchmarking requirements. See the examples in # Benchmark, and the #bm and #bmbm methods. # # Example: # # require 'benchmark' # include Benchmark # we need the CAPTION and FORMAT constants # # n = 50000 # Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x| # tf = x.report("for:") { for i in 1..n; a = "1"; end } # tt = x.report("times:") { n.times do ; a = "1"; end } # tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end } # [tf+tt+tu, (tf+tt+tu)/3] # end # # <i>Generates:</i> # # user system total real # for: 1.016667 0.016667 1.033333 ( 0.485749) # times: 1.450000 0.016667 1.466667 ( 0.681367) # upto: 1.533333 0.000000 1.533333 ( 0.722166) # >total: 4.000000 0.033333 4.033333 ( 1.889282) # >avg: 1.333333 0.011111 1.344444 ( 0.629761) # def benchmark(caption = "", label_width = nil, format = nil, *labels) # :yield: report sync = STDOUT.sync STDOUT.sync = true label_width ||= 0 label_width += 1 format ||= FORMAT print ' '*label_width + caption report = Report.new(label_width, format) results = yield(report) Array === results and results.grep(Tms).each {|t| print((labels.shift || t.label || "").ljust(label_width), t.format(format)) } report.list ensure STDOUT.sync = sync unless sync.nil? end # A simple interface to the #benchmark method, #bm is generates sequential reports # with labels. The parameters have the same meaning as for #benchmark. # # require 'benchmark' # # n = 50000 # Benchmark.bm(7) do |x| # x.report("for:") { for i in 1..n; a = "1"; end } # x.report("times:") { n.times do ; a = "1"; end } # x.report("upto:") { 1.upto(n) do ; a = "1"; end } # end # # <i>Generates:</i> # # user system total real # for: 1.050000 0.000000 1.050000 ( 0.503462) # times: 1.533333 0.016667 1.550000 ( 0.735473) # upto: 1.500000 0.016667 1.516667 ( 0.711239) # def bm(label_width = 0, *labels, &blk) # :yield: report benchmark(CAPTION, label_width, FORMAT, *labels, &blk) end # Sometimes benchmark results are skewed because code executed # earlier encounters different garbage collection overheads than # that run later. #bmbm attempts to minimize this effect by running # the tests twice, the first time as a rehearsal in order to get the # runtime environment stable, the second time for # real. <tt>GC.start</tt> is executed before the start of each of # the real timings; the cost of this is not included in the # timings. In reality, though, there's only so much that #bmbm can # do, and the results are not guaranteed to be isolated from garbage # collection and other effects. # # Because #bmbm takes two passes through the tests, it can # calculate the required label width. # # require 'benchmark' # # array = (1..1000000).map { rand } # # Benchmark.bmbm do |x| # x.report("sort!") { array.dup.sort! } # x.report("sort") { array.dup.sort } # end # # <i>Generates:</i> # # Rehearsal ----------------------------------------- # sort! 11.928000 0.010000 11.938000 ( 12.756000) # sort 13.048000 0.020000 13.068000 ( 13.857000) # ------------------------------- total: 25.006000sec # # user system total real # sort! 12.959000 0.010000 12.969000 ( 13.793000) # sort 12.007000 0.000000 12.007000 ( 12.791000) # # #bmbm yields a Benchmark::Job object and returns an array of # Benchmark::Tms objects. # def bmbm(width = 0, &blk) # :yield: job job = Job.new(width) yield(job) width = job.width + 1 sync = STDOUT.sync STDOUT.sync = true # rehearsal puts 'Rehearsal '.ljust(width+CAPTION.length,'-') ets = job.list.inject(Tms.new) { |sum,(label,item)| print label.ljust(width) res = Benchmark.measure(&item) print res.format sum + res }.format("total: %tsec") print " #{ets}\n\n".rjust(width+CAPTION.length+2,'-') # take print ' '*width + CAPTION job.list.map { |label,item| GC.start print label.ljust(width) Benchmark.measure(label, &item).tap { |res| print res } } ensure STDOUT.sync = sync unless sync.nil? end # # Returns the time used to execute the given block as a # Benchmark::Tms object. # def measure(label = "") # :yield: t0, r0 = Process.times, Time.now yield t1, r1 = Process.times, Time.now Benchmark::Tms.new(t1.utime - t0.utime, t1.stime - t0.stime, t1.cutime - t0.cutime, t1.cstime - t0.cstime, r1.to_f - r0.to_f, label) end # # Returns the elapsed real time used to execute the given block. # def realtime # :yield: r0 = Time.now yield Time.now - r0 end module_function :benchmark, :measure, :realtime, :bm, :bmbm # # A Job is a sequence of labelled blocks to be processed by the # Benchmark.bmbm method. It is of little direct interest to the user. # class Job # :nodoc: # # Returns an initialized Job instance. # Usually, one doesn't call this method directly, as new # Job objects are created by the #bmbm method. # _width_ is a initial value for the label offset used in formatting; # the #bmbm method passes its _width_ argument to this constructor. # def initialize(width) @width = width @list = [] end # # Registers the given label and block pair in the job list. # def item(label = "", &blk) # :yield: raise ArgumentError, "no block" unless block_given? label = label.to_s w = label.length @width = w if @width < w @list << [label, blk] self end alias report item # An array of 2-element arrays, consisting of label and block pairs. attr_reader :list # Length of the widest label in the #list. attr_reader :width end # # This class is used by the Benchmark.benchmark and Benchmark.bm methods. # It is of little direct interest to the user. # class Report # :nodoc: # # Returns an initialized Report instance. # Usually, one doesn't call this method directly, as new # Report objects are created by the #benchmark and #bm methods. # _width_ and _format_ are the label offset and # format string used by Tms#format. # def initialize(width = 0, format = nil) @width, @format, @list = width, format, [] end # # Prints the _label_ and measured time for the block, # formatted by _format_. See Tms#format for the # formatting rules. # def item(label = "", *format, &blk) # :yield: print label.to_s.ljust(@width) @list << res = Benchmark.measure(label, &blk) print res.format(@format, *format) res end alias report item # An array of Benchmark::Tms objects representing each item. attr_reader :list end # # A data object, representing the times associated with a benchmark # measurement. # class Tms # Default caption, see also Benchmark::CAPTION CAPTION = " user system total real\n" # Default format string, see also Benchmark::FORMAT FORMAT = "%10.6u %10.6y %10.6t %10.6r\n" # User CPU time attr_reader :utime # System CPU time attr_reader :stime # User CPU time of children attr_reader :cutime # System CPU time of children attr_reader :cstime # Elapsed real time attr_reader :real # Total time, that is _utime_ + _stime_ + _cutime_ + _cstime_ attr_reader :total # Label attr_reader :label # # Returns an initialized Tms object which has # _utime_ as the user CPU time, _stime_ as the system CPU time, # _cutime_ as the children's user CPU time, _cstime_ as the children's # system CPU time, _real_ as the elapsed real time and _label_ as the label. # def initialize(utime = 0.0, stime = 0.0, cutime = 0.0, cstime = 0.0, real = 0.0, label = nil) @utime, @stime, @cutime, @cstime, @real, @label = utime, stime, cutime, cstime, real, label.to_s @total = @utime + @stime + @cutime + @cstime end # # Returns a new Tms object whose times are the sum of the times for this # Tms object, plus the time required to execute the code block (_blk_). # def add(&blk) # :yield: self + Benchmark.measure(&blk) end # # An in-place version of #add. # def add!(&blk) t = Benchmark.measure(&blk) @utime = utime + t.utime @stime = stime + t.stime @cutime = cutime + t.cutime @cstime = cstime + t.cstime @real = real + t.real self end # # Returns a new Tms object obtained by memberwise summation # of the individual times for this Tms object with those of the other # Tms object. # This method and #/() are useful for taking statistics. # def +(other); memberwise(:+, other) end # # Returns a new Tms object obtained by memberwise subtraction # of the individual times for the other Tms object from those of this # Tms object. # def -(other); memberwise(:-, other) end # # Returns a new Tms object obtained by memberwise multiplication # of the individual times for this Tms object by _x_. # def *(x); memberwise(:*, x) end # # Returns a new Tms object obtained by memberwise division # of the individual times for this Tms object by _x_. # This method and #+() are useful for taking statistics. # def /(x); memberwise(:/, x) end # # Returns the contents of this Tms object as # a formatted string, according to a format string # like that passed to Kernel.format. In addition, #format # accepts the following extensions: # # <tt>%u</tt>:: Replaced by the user CPU time, as reported by Tms#utime. # <tt>%y</tt>:: Replaced by the system CPU time, as reported by #stime (Mnemonic: y of "s*y*stem") # <tt>%U</tt>:: Replaced by the children's user CPU time, as reported by Tms#cutime # <tt>%Y</tt>:: Replaced by the children's system CPU time, as reported by Tms#cstime # <tt>%t</tt>:: Replaced by the total CPU time, as reported by Tms#total # <tt>%r</tt>:: Replaced by the elapsed real time, as reported by Tms#real # <tt>%n</tt>:: Replaced by the label string, as reported by Tms#label (Mnemonic: n of "*n*ame") # # If _format_ is not given, FORMAT is used as default value, detailing the # user, system and real elapsed time. # def format(format = nil, *args) str = (format || FORMAT).dup str.gsub!(/(%[-+\.\d]*)n/) { "#{$1}s" % label } str.gsub!(/(%[-+\.\d]*)u/) { "#{$1}f" % utime } str.gsub!(/(%[-+\.\d]*)y/) { "#{$1}f" % stime } str.gsub!(/(%[-+\.\d]*)U/) { "#{$1}f" % cutime } str.gsub!(/(%[-+\.\d]*)Y/) { "#{$1}f" % cstime } str.gsub!(/(%[-+\.\d]*)t/) { "#{$1}f" % total } str.gsub!(/(%[-+\.\d]*)r/) { "(#{$1}f)" % real } format ? str % args : str end # # Same as #format. # def to_s format end # # Returns a new 6-element array, consisting of the # label, user CPU time, system CPU time, children's # user CPU time, children's system CPU time and elapsed # real time. # def to_a [@label, @utime, @stime, @cutime, @cstime, @real] end protected # # Returns a new Tms object obtained by memberwise operation +op+ # of the individual times for this Tms object with those of the other # Tms object. # # +op+ can be a mathematical operation such as <tt>+</tt>, <tt>-</tt>, # <tt>*</tt>, <tt>/</tt> # def memberwise(op, x) case x when Benchmark::Tms Benchmark::Tms.new(utime.__send__(op, x.utime), stime.__send__(op, x.stime), cutime.__send__(op, x.cutime), cstime.__send__(op, x.cstime), real.__send__(op, x.real) ) else Benchmark::Tms.new(utime.__send__(op, x), stime.__send__(op, x), cutime.__send__(op, x), cstime.__send__(op, x), real.__send__(op, x) ) end end end # The default caption string (heading above the output times). CAPTION = Benchmark::Tms::CAPTION # The default format string used to display times. See also Benchmark::Tms#format. FORMAT = Benchmark::Tms::FORMAT end if __FILE__ == $0 include Benchmark n = ARGV[0].to_i.nonzero? || 50000 puts %Q([#{n} times iterations of `a = "1"']) benchmark(" " + CAPTION, 7, FORMAT) do |x| x.report("for:") {for _ in 1..n; _ = "1"; end} # Benchmark.measure x.report("times:") {n.times do ; _ = "1"; end} x.report("upto:") {1.upto(n) do ; _ = "1"; end} end benchmark do [ measure{for _ in 1..n; _ = "1"; end}, # Benchmark.measure measure{n.times do ; _ = "1"; end}, measure{1.upto(n) do ; _ = "1"; end} ] end end
SILENT KILLER Tool