Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby32/share/ruby
File: benchmark.rb
# frozen_string_literal: true
[0] Fix | Delete
#--
[1] Fix | Delete
# benchmark.rb - a performance benchmarking library
[2] Fix | Delete
#
[3] Fix | Delete
# $Id$
[4] Fix | Delete
#
[5] Fix | Delete
# Created by Gotoken (gotoken@notwork.org).
[6] Fix | Delete
#
[7] Fix | Delete
# Documentation by Gotoken (original RD), Lyle Johnson (RDoc conversion), and
[8] Fix | Delete
# Gavin Sinclair (editing).
[9] Fix | Delete
#++
[10] Fix | Delete
#
[11] Fix | Delete
# == Overview
[12] Fix | Delete
#
[13] Fix | Delete
# The Benchmark module provides methods for benchmarking Ruby code, giving
[14] Fix | Delete
# detailed reports on the time taken for each task.
[15] Fix | Delete
#
[16] Fix | Delete
[17] Fix | Delete
# The Benchmark module provides methods to measure and report the time
[18] Fix | Delete
# used to execute Ruby code.
[19] Fix | Delete
#
[20] Fix | Delete
# * Measure the time to construct the string given by the expression
[21] Fix | Delete
# <code>"a"*1_000_000_000</code>:
[22] Fix | Delete
#
[23] Fix | Delete
# require 'benchmark'
[24] Fix | Delete
#
[25] Fix | Delete
# puts Benchmark.measure { "a"*1_000_000_000 }
[26] Fix | Delete
#
[27] Fix | Delete
# On my machine (OSX 10.8.3 on i5 1.7 GHz) this generates:
[28] Fix | Delete
#
[29] Fix | Delete
# 0.350000 0.400000 0.750000 ( 0.835234)
[30] Fix | Delete
#
[31] Fix | Delete
# This report shows the user CPU time, system CPU time, the sum of
[32] Fix | Delete
# the user and system CPU times, and the elapsed real time. The unit
[33] Fix | Delete
# of time is seconds.
[34] Fix | Delete
#
[35] Fix | Delete
# * Do some experiments sequentially using the #bm method:
[36] Fix | Delete
#
[37] Fix | Delete
# require 'benchmark'
[38] Fix | Delete
#
[39] Fix | Delete
# n = 5000000
[40] Fix | Delete
# Benchmark.bm do |x|
[41] Fix | Delete
# x.report { for i in 1..n; a = "1"; end }
[42] Fix | Delete
# x.report { n.times do ; a = "1"; end }
[43] Fix | Delete
# x.report { 1.upto(n) do ; a = "1"; end }
[44] Fix | Delete
# end
[45] Fix | Delete
#
[46] Fix | Delete
# The result:
[47] Fix | Delete
#
[48] Fix | Delete
# user system total real
[49] Fix | Delete
# 1.010000 0.000000 1.010000 ( 1.014479)
[50] Fix | Delete
# 1.000000 0.000000 1.000000 ( 0.998261)
[51] Fix | Delete
# 0.980000 0.000000 0.980000 ( 0.981335)
[52] Fix | Delete
#
[53] Fix | Delete
# * Continuing the previous example, put a label in each report:
[54] Fix | Delete
#
[55] Fix | Delete
# require 'benchmark'
[56] Fix | Delete
#
[57] Fix | Delete
# n = 5000000
[58] Fix | Delete
# Benchmark.bm(7) do |x|
[59] Fix | Delete
# x.report("for:") { for i in 1..n; a = "1"; end }
[60] Fix | Delete
# x.report("times:") { n.times do ; a = "1"; end }
[61] Fix | Delete
# x.report("upto:") { 1.upto(n) do ; a = "1"; end }
[62] Fix | Delete
# end
[63] Fix | Delete
#
[64] Fix | Delete
# The result:
[65] Fix | Delete
#
[66] Fix | Delete
# user system total real
[67] Fix | Delete
# for: 1.010000 0.000000 1.010000 ( 1.015688)
[68] Fix | Delete
# times: 1.000000 0.000000 1.000000 ( 1.003611)
[69] Fix | Delete
# upto: 1.030000 0.000000 1.030000 ( 1.028098)
[70] Fix | Delete
#
[71] Fix | Delete
# * The times for some benchmarks depend on the order in which items
[72] Fix | Delete
# are run. These differences are due to the cost of memory
[73] Fix | Delete
# allocation and garbage collection. To avoid these discrepancies,
[74] Fix | Delete
# the #bmbm method is provided. For example, to compare ways to
[75] Fix | Delete
# sort an array of floats:
[76] Fix | Delete
#
[77] Fix | Delete
# require 'benchmark'
[78] Fix | Delete
#
[79] Fix | Delete
# array = (1..1000000).map { rand }
[80] Fix | Delete
#
[81] Fix | Delete
# Benchmark.bmbm do |x|
[82] Fix | Delete
# x.report("sort!") { array.dup.sort! }
[83] Fix | Delete
# x.report("sort") { array.dup.sort }
[84] Fix | Delete
# end
[85] Fix | Delete
#
[86] Fix | Delete
# The result:
[87] Fix | Delete
#
[88] Fix | Delete
# Rehearsal -----------------------------------------
[89] Fix | Delete
# sort! 1.490000 0.010000 1.500000 ( 1.490520)
[90] Fix | Delete
# sort 1.460000 0.000000 1.460000 ( 1.463025)
[91] Fix | Delete
# -------------------------------- total: 2.960000sec
[92] Fix | Delete
#
[93] Fix | Delete
# user system total real
[94] Fix | Delete
# sort! 1.460000 0.000000 1.460000 ( 1.460465)
[95] Fix | Delete
# sort 1.450000 0.010000 1.460000 ( 1.448327)
[96] Fix | Delete
#
[97] Fix | Delete
# * Report statistics of sequential experiments with unique labels,
[98] Fix | Delete
# using the #benchmark method:
[99] Fix | Delete
#
[100] Fix | Delete
# require 'benchmark'
[101] Fix | Delete
# include Benchmark # we need the CAPTION and FORMAT constants
[102] Fix | Delete
#
[103] Fix | Delete
# n = 5000000
[104] Fix | Delete
# Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
[105] Fix | Delete
# tf = x.report("for:") { for i in 1..n; a = "1"; end }
[106] Fix | Delete
# tt = x.report("times:") { n.times do ; a = "1"; end }
[107] Fix | Delete
# tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
[108] Fix | Delete
# [tf+tt+tu, (tf+tt+tu)/3]
[109] Fix | Delete
# end
[110] Fix | Delete
#
[111] Fix | Delete
# The result:
[112] Fix | Delete
#
[113] Fix | Delete
# user system total real
[114] Fix | Delete
# for: 0.950000 0.000000 0.950000 ( 0.952039)
[115] Fix | Delete
# times: 0.980000 0.000000 0.980000 ( 0.984938)
[116] Fix | Delete
# upto: 0.950000 0.000000 0.950000 ( 0.946787)
[117] Fix | Delete
# >total: 2.880000 0.000000 2.880000 ( 2.883764)
[118] Fix | Delete
# >avg: 0.960000 0.000000 0.960000 ( 0.961255)
[119] Fix | Delete
[120] Fix | Delete
module Benchmark
[121] Fix | Delete
[122] Fix | Delete
BENCHMARK_VERSION = "2002-04-25" # :nodoc:
[123] Fix | Delete
[124] Fix | Delete
# Invokes the block with a Benchmark::Report object, which
[125] Fix | Delete
# may be used to collect and report on the results of individual
[126] Fix | Delete
# benchmark tests. Reserves +label_width+ leading spaces for
[127] Fix | Delete
# labels on each line. Prints +caption+ at the top of the
[128] Fix | Delete
# report, and uses +format+ to format each line.
[129] Fix | Delete
# (Note: +caption+ must contain a terminating newline character,
[130] Fix | Delete
# see the default Benchmark::Tms::CAPTION for an example.)
[131] Fix | Delete
#
[132] Fix | Delete
# Returns an array of Benchmark::Tms objects.
[133] Fix | Delete
#
[134] Fix | Delete
# If the block returns an array of
[135] Fix | Delete
# Benchmark::Tms objects, these will be used to format
[136] Fix | Delete
# additional lines of output. If +labels+ parameter are
[137] Fix | Delete
# given, these are used to label these extra lines.
[138] Fix | Delete
#
[139] Fix | Delete
# _Note_: Other methods provide a simpler interface to this one, and are
[140] Fix | Delete
# suitable for nearly all benchmarking requirements. See the examples in
[141] Fix | Delete
# Benchmark, and the #bm and #bmbm methods.
[142] Fix | Delete
#
[143] Fix | Delete
# Example:
[144] Fix | Delete
#
[145] Fix | Delete
# require 'benchmark'
[146] Fix | Delete
# include Benchmark # we need the CAPTION and FORMAT constants
[147] Fix | Delete
#
[148] Fix | Delete
# n = 5000000
[149] Fix | Delete
# Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
[150] Fix | Delete
# tf = x.report("for:") { for i in 1..n; a = "1"; end }
[151] Fix | Delete
# tt = x.report("times:") { n.times do ; a = "1"; end }
[152] Fix | Delete
# tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
[153] Fix | Delete
# [tf+tt+tu, (tf+tt+tu)/3]
[154] Fix | Delete
# end
[155] Fix | Delete
#
[156] Fix | Delete
# Generates:
[157] Fix | Delete
#
[158] Fix | Delete
# user system total real
[159] Fix | Delete
# for: 0.970000 0.000000 0.970000 ( 0.970493)
[160] Fix | Delete
# times: 0.990000 0.000000 0.990000 ( 0.989542)
[161] Fix | Delete
# upto: 0.970000 0.000000 0.970000 ( 0.972854)
[162] Fix | Delete
# >total: 2.930000 0.000000 2.930000 ( 2.932889)
[163] Fix | Delete
# >avg: 0.976667 0.000000 0.976667 ( 0.977630)
[164] Fix | Delete
#
[165] Fix | Delete
[166] Fix | Delete
def benchmark(caption = "", label_width = nil, format = nil, *labels) # :yield: report
[167] Fix | Delete
sync = $stdout.sync
[168] Fix | Delete
$stdout.sync = true
[169] Fix | Delete
label_width ||= 0
[170] Fix | Delete
label_width += 1
[171] Fix | Delete
format ||= FORMAT
[172] Fix | Delete
print ' '*label_width + caption unless caption.empty?
[173] Fix | Delete
report = Report.new(label_width, format)
[174] Fix | Delete
results = yield(report)
[175] Fix | Delete
Array === results and results.grep(Tms).each {|t|
[176] Fix | Delete
print((labels.shift || t.label || "").ljust(label_width), t.format(format))
[177] Fix | Delete
}
[178] Fix | Delete
report.list
[179] Fix | Delete
ensure
[180] Fix | Delete
$stdout.sync = sync unless sync.nil?
[181] Fix | Delete
end
[182] Fix | Delete
[183] Fix | Delete
[184] Fix | Delete
# A simple interface to the #benchmark method, #bm generates sequential
[185] Fix | Delete
# reports with labels. +label_width+ and +labels+ parameters have the same
[186] Fix | Delete
# meaning as for #benchmark.
[187] Fix | Delete
#
[188] Fix | Delete
# require 'benchmark'
[189] Fix | Delete
#
[190] Fix | Delete
# n = 5000000
[191] Fix | Delete
# Benchmark.bm(7) do |x|
[192] Fix | Delete
# x.report("for:") { for i in 1..n; a = "1"; end }
[193] Fix | Delete
# x.report("times:") { n.times do ; a = "1"; end }
[194] Fix | Delete
# x.report("upto:") { 1.upto(n) do ; a = "1"; end }
[195] Fix | Delete
# end
[196] Fix | Delete
#
[197] Fix | Delete
# Generates:
[198] Fix | Delete
#
[199] Fix | Delete
# user system total real
[200] Fix | Delete
# for: 0.960000 0.000000 0.960000 ( 0.957966)
[201] Fix | Delete
# times: 0.960000 0.000000 0.960000 ( 0.960423)
[202] Fix | Delete
# upto: 0.950000 0.000000 0.950000 ( 0.954864)
[203] Fix | Delete
#
[204] Fix | Delete
[205] Fix | Delete
def bm(label_width = 0, *labels, &blk) # :yield: report
[206] Fix | Delete
benchmark(CAPTION, label_width, FORMAT, *labels, &blk)
[207] Fix | Delete
end
[208] Fix | Delete
[209] Fix | Delete
[210] Fix | Delete
# Sometimes benchmark results are skewed because code executed
[211] Fix | Delete
# earlier encounters different garbage collection overheads than
[212] Fix | Delete
# that run later. #bmbm attempts to minimize this effect by running
[213] Fix | Delete
# the tests twice, the first time as a rehearsal in order to get the
[214] Fix | Delete
# runtime environment stable, the second time for
[215] Fix | Delete
# real. GC.start is executed before the start of each of
[216] Fix | Delete
# the real timings; the cost of this is not included in the
[217] Fix | Delete
# timings. In reality, though, there's only so much that #bmbm can
[218] Fix | Delete
# do, and the results are not guaranteed to be isolated from garbage
[219] Fix | Delete
# collection and other effects.
[220] Fix | Delete
#
[221] Fix | Delete
# Because #bmbm takes two passes through the tests, it can
[222] Fix | Delete
# calculate the required label width.
[223] Fix | Delete
#
[224] Fix | Delete
# require 'benchmark'
[225] Fix | Delete
#
[226] Fix | Delete
# array = (1..1000000).map { rand }
[227] Fix | Delete
#
[228] Fix | Delete
# Benchmark.bmbm do |x|
[229] Fix | Delete
# x.report("sort!") { array.dup.sort! }
[230] Fix | Delete
# x.report("sort") { array.dup.sort }
[231] Fix | Delete
# end
[232] Fix | Delete
#
[233] Fix | Delete
# Generates:
[234] Fix | Delete
#
[235] Fix | Delete
# Rehearsal -----------------------------------------
[236] Fix | Delete
# sort! 1.440000 0.010000 1.450000 ( 1.446833)
[237] Fix | Delete
# sort 1.440000 0.000000 1.440000 ( 1.448257)
[238] Fix | Delete
# -------------------------------- total: 2.890000sec
[239] Fix | Delete
#
[240] Fix | Delete
# user system total real
[241] Fix | Delete
# sort! 1.460000 0.000000 1.460000 ( 1.458065)
[242] Fix | Delete
# sort 1.450000 0.000000 1.450000 ( 1.455963)
[243] Fix | Delete
#
[244] Fix | Delete
# #bmbm yields a Benchmark::Job object and returns an array of
[245] Fix | Delete
# Benchmark::Tms objects.
[246] Fix | Delete
#
[247] Fix | Delete
def bmbm(width = 0) # :yield: job
[248] Fix | Delete
job = Job.new(width)
[249] Fix | Delete
yield(job)
[250] Fix | Delete
width = job.width + 1
[251] Fix | Delete
sync = $stdout.sync
[252] Fix | Delete
$stdout.sync = true
[253] Fix | Delete
[254] Fix | Delete
# rehearsal
[255] Fix | Delete
puts 'Rehearsal '.ljust(width+CAPTION.length,'-')
[256] Fix | Delete
ets = job.list.inject(Tms.new) { |sum,(label,item)|
[257] Fix | Delete
print label.ljust(width)
[258] Fix | Delete
res = Benchmark.measure(&item)
[259] Fix | Delete
print res.format
[260] Fix | Delete
sum + res
[261] Fix | Delete
}.format("total: %tsec")
[262] Fix | Delete
print " #{ets}\n\n".rjust(width+CAPTION.length+2,'-')
[263] Fix | Delete
[264] Fix | Delete
# take
[265] Fix | Delete
print ' '*width + CAPTION
[266] Fix | Delete
job.list.map { |label,item|
[267] Fix | Delete
GC.start
[268] Fix | Delete
print label.ljust(width)
[269] Fix | Delete
Benchmark.measure(label, &item).tap { |res| print res }
[270] Fix | Delete
}
[271] Fix | Delete
ensure
[272] Fix | Delete
$stdout.sync = sync unless sync.nil?
[273] Fix | Delete
end
[274] Fix | Delete
[275] Fix | Delete
#
[276] Fix | Delete
# Returns the time used to execute the given block as a
[277] Fix | Delete
# Benchmark::Tms object. Takes +label+ option.
[278] Fix | Delete
#
[279] Fix | Delete
# require 'benchmark'
[280] Fix | Delete
#
[281] Fix | Delete
# n = 1000000
[282] Fix | Delete
#
[283] Fix | Delete
# time = Benchmark.measure do
[284] Fix | Delete
# n.times { a = "1" }
[285] Fix | Delete
# end
[286] Fix | Delete
# puts time
[287] Fix | Delete
#
[288] Fix | Delete
# Generates:
[289] Fix | Delete
#
[290] Fix | Delete
# 0.220000 0.000000 0.220000 ( 0.227313)
[291] Fix | Delete
#
[292] Fix | Delete
def measure(label = "") # :yield:
[293] Fix | Delete
t0, r0 = Process.times, Process.clock_gettime(Process::CLOCK_MONOTONIC)
[294] Fix | Delete
yield
[295] Fix | Delete
t1, r1 = Process.times, Process.clock_gettime(Process::CLOCK_MONOTONIC)
[296] Fix | Delete
Benchmark::Tms.new(t1.utime - t0.utime,
[297] Fix | Delete
t1.stime - t0.stime,
[298] Fix | Delete
t1.cutime - t0.cutime,
[299] Fix | Delete
t1.cstime - t0.cstime,
[300] Fix | Delete
r1 - r0,
[301] Fix | Delete
label)
[302] Fix | Delete
end
[303] Fix | Delete
[304] Fix | Delete
#
[305] Fix | Delete
# Returns the elapsed real time used to execute the given block.
[306] Fix | Delete
#
[307] Fix | Delete
def realtime # :yield:
[308] Fix | Delete
r0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
[309] Fix | Delete
yield
[310] Fix | Delete
Process.clock_gettime(Process::CLOCK_MONOTONIC) - r0
[311] Fix | Delete
end
[312] Fix | Delete
[313] Fix | Delete
module_function :benchmark, :measure, :realtime, :bm, :bmbm
[314] Fix | Delete
[315] Fix | Delete
#
[316] Fix | Delete
# A Job is a sequence of labelled blocks to be processed by the
[317] Fix | Delete
# Benchmark.bmbm method. It is of little direct interest to the user.
[318] Fix | Delete
#
[319] Fix | Delete
class Job # :nodoc:
[320] Fix | Delete
#
[321] Fix | Delete
# Returns an initialized Job instance.
[322] Fix | Delete
# Usually, one doesn't call this method directly, as new
[323] Fix | Delete
# Job objects are created by the #bmbm method.
[324] Fix | Delete
# +width+ is a initial value for the label offset used in formatting;
[325] Fix | Delete
# the #bmbm method passes its +width+ argument to this constructor.
[326] Fix | Delete
#
[327] Fix | Delete
def initialize(width)
[328] Fix | Delete
@width = width
[329] Fix | Delete
@list = []
[330] Fix | Delete
end
[331] Fix | Delete
[332] Fix | Delete
#
[333] Fix | Delete
# Registers the given label and block pair in the job list.
[334] Fix | Delete
#
[335] Fix | Delete
def item(label = "", &blk) # :yield:
[336] Fix | Delete
raise ArgumentError, "no block" unless block_given?
[337] Fix | Delete
label = label.to_s
[338] Fix | Delete
w = label.length
[339] Fix | Delete
@width = w if @width < w
[340] Fix | Delete
@list << [label, blk]
[341] Fix | Delete
self
[342] Fix | Delete
end
[343] Fix | Delete
[344] Fix | Delete
alias report item
[345] Fix | Delete
[346] Fix | Delete
# An array of 2-element arrays, consisting of label and block pairs.
[347] Fix | Delete
attr_reader :list
[348] Fix | Delete
[349] Fix | Delete
# Length of the widest label in the #list.
[350] Fix | Delete
attr_reader :width
[351] Fix | Delete
end
[352] Fix | Delete
[353] Fix | Delete
#
[354] Fix | Delete
# This class is used by the Benchmark.benchmark and Benchmark.bm methods.
[355] Fix | Delete
# It is of little direct interest to the user.
[356] Fix | Delete
#
[357] Fix | Delete
class Report # :nodoc:
[358] Fix | Delete
#
[359] Fix | Delete
# Returns an initialized Report instance.
[360] Fix | Delete
# Usually, one doesn't call this method directly, as new
[361] Fix | Delete
# Report objects are created by the #benchmark and #bm methods.
[362] Fix | Delete
# +width+ and +format+ are the label offset and
[363] Fix | Delete
# format string used by Tms#format.
[364] Fix | Delete
#
[365] Fix | Delete
def initialize(width = 0, format = nil)
[366] Fix | Delete
@width, @format, @list = width, format, []
[367] Fix | Delete
end
[368] Fix | Delete
[369] Fix | Delete
#
[370] Fix | Delete
# Prints the +label+ and measured time for the block,
[371] Fix | Delete
# formatted by +format+. See Tms#format for the
[372] Fix | Delete
# formatting rules.
[373] Fix | Delete
#
[374] Fix | Delete
def item(label = "", *format, &blk) # :yield:
[375] Fix | Delete
print label.to_s.ljust(@width)
[376] Fix | Delete
@list << res = Benchmark.measure(label, &blk)
[377] Fix | Delete
print res.format(@format, *format)
[378] Fix | Delete
res
[379] Fix | Delete
end
[380] Fix | Delete
[381] Fix | Delete
alias report item
[382] Fix | Delete
[383] Fix | Delete
# An array of Benchmark::Tms objects representing each item.
[384] Fix | Delete
attr_reader :list
[385] Fix | Delete
end
[386] Fix | Delete
[387] Fix | Delete
[388] Fix | Delete
[389] Fix | Delete
#
[390] Fix | Delete
# A data object, representing the times associated with a benchmark
[391] Fix | Delete
# measurement.
[392] Fix | Delete
#
[393] Fix | Delete
class Tms
[394] Fix | Delete
[395] Fix | Delete
# Default caption, see also Benchmark::CAPTION
[396] Fix | Delete
CAPTION = " user system total real\n"
[397] Fix | Delete
[398] Fix | Delete
# Default format string, see also Benchmark::FORMAT
[399] Fix | Delete
FORMAT = "%10.6u %10.6y %10.6t %10.6r\n"
[400] Fix | Delete
[401] Fix | Delete
# User CPU time
[402] Fix | Delete
attr_reader :utime
[403] Fix | Delete
[404] Fix | Delete
# System CPU time
[405] Fix | Delete
attr_reader :stime
[406] Fix | Delete
[407] Fix | Delete
# User CPU time of children
[408] Fix | Delete
attr_reader :cutime
[409] Fix | Delete
[410] Fix | Delete
# System CPU time of children
[411] Fix | Delete
attr_reader :cstime
[412] Fix | Delete
[413] Fix | Delete
# Elapsed real time
[414] Fix | Delete
attr_reader :real
[415] Fix | Delete
[416] Fix | Delete
# Total time, that is +utime+ + +stime+ + +cutime+ + +cstime+
[417] Fix | Delete
attr_reader :total
[418] Fix | Delete
[419] Fix | Delete
# Label
[420] Fix | Delete
attr_reader :label
[421] Fix | Delete
[422] Fix | Delete
#
[423] Fix | Delete
# Returns an initialized Tms object which has
[424] Fix | Delete
# +utime+ as the user CPU time, +stime+ as the system CPU time,
[425] Fix | Delete
# +cutime+ as the children's user CPU time, +cstime+ as the children's
[426] Fix | Delete
# system CPU time, +real+ as the elapsed real time and +label+ as the label.
[427] Fix | Delete
#
[428] Fix | Delete
def initialize(utime = 0.0, stime = 0.0, cutime = 0.0, cstime = 0.0, real = 0.0, label = nil)
[429] Fix | Delete
@utime, @stime, @cutime, @cstime, @real, @label = utime, stime, cutime, cstime, real, label.to_s
[430] Fix | Delete
@total = @utime + @stime + @cutime + @cstime
[431] Fix | Delete
end
[432] Fix | Delete
[433] Fix | Delete
#
[434] Fix | Delete
# Returns a new Tms object whose times are the sum of the times for this
[435] Fix | Delete
# Tms object, plus the time required to execute the code block (+blk+).
[436] Fix | Delete
#
[437] Fix | Delete
def add(&blk) # :yield:
[438] Fix | Delete
self + Benchmark.measure(&blk)
[439] Fix | Delete
end
[440] Fix | Delete
[441] Fix | Delete
#
[442] Fix | Delete
# An in-place version of #add.
[443] Fix | Delete
# Changes the times of this Tms object by making it the sum of the times
[444] Fix | Delete
# for this Tms object, plus the time required to execute
[445] Fix | Delete
# the code block (+blk+).
[446] Fix | Delete
#
[447] Fix | Delete
def add!(&blk)
[448] Fix | Delete
t = Benchmark.measure(&blk)
[449] Fix | Delete
@utime = utime + t.utime
[450] Fix | Delete
@stime = stime + t.stime
[451] Fix | Delete
@cutime = cutime + t.cutime
[452] Fix | Delete
@cstime = cstime + t.cstime
[453] Fix | Delete
@real = real + t.real
[454] Fix | Delete
self
[455] Fix | Delete
end
[456] Fix | Delete
[457] Fix | Delete
#
[458] Fix | Delete
# Returns a new Tms object obtained by memberwise summation
[459] Fix | Delete
# of the individual times for this Tms object with those of the +other+
[460] Fix | Delete
# Tms object.
[461] Fix | Delete
# This method and #/() are useful for taking statistics.
[462] Fix | Delete
#
[463] Fix | Delete
def +(other); memberwise(:+, other) end
[464] Fix | Delete
[465] Fix | Delete
#
[466] Fix | Delete
# Returns a new Tms object obtained by memberwise subtraction
[467] Fix | Delete
# of the individual times for the +other+ Tms object from those of this
[468] Fix | Delete
# Tms object.
[469] Fix | Delete
#
[470] Fix | Delete
def -(other); memberwise(:-, other) end
[471] Fix | Delete
[472] Fix | Delete
#
[473] Fix | Delete
# Returns a new Tms object obtained by memberwise multiplication
[474] Fix | Delete
# of the individual times for this Tms object by +x+.
[475] Fix | Delete
#
[476] Fix | Delete
def *(x); memberwise(:*, x) end
[477] Fix | Delete
[478] Fix | Delete
#
[479] Fix | Delete
# Returns a new Tms object obtained by memberwise division
[480] Fix | Delete
# of the individual times for this Tms object by +x+.
[481] Fix | Delete
# This method and #+() are useful for taking statistics.
[482] Fix | Delete
#
[483] Fix | Delete
def /(x); memberwise(:/, x) end
[484] Fix | Delete
[485] Fix | Delete
#
[486] Fix | Delete
# Returns the contents of this Tms object as
[487] Fix | Delete
# a formatted string, according to a +format+ string
[488] Fix | Delete
# like that passed to Kernel.format. In addition, #format
[489] Fix | Delete
# accepts the following extensions:
[490] Fix | Delete
#
[491] Fix | Delete
# <tt>%u</tt>:: Replaced by the user CPU time, as reported by Tms#utime.
[492] Fix | Delete
# <tt>%y</tt>:: Replaced by the system CPU time, as reported by #stime (Mnemonic: y of "s*y*stem")
[493] Fix | Delete
# <tt>%U</tt>:: Replaced by the children's user CPU time, as reported by Tms#cutime
[494] Fix | Delete
# <tt>%Y</tt>:: Replaced by the children's system CPU time, as reported by Tms#cstime
[495] Fix | Delete
# <tt>%t</tt>:: Replaced by the total CPU time, as reported by Tms#total
[496] Fix | Delete
# <tt>%r</tt>:: Replaced by the elapsed real time, as reported by Tms#real
[497] Fix | Delete
# <tt>%n</tt>:: Replaced by the label string, as reported by Tms#label (Mnemonic: n of "*n*ame")
[498] Fix | Delete
#
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function