Invokes the block with a Benchmark::Report object, which may be used to collect and report on the results of individual benchmark tests. Reserves label_width
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 Benchmark::Tms
objects, these will be used to format additional lines of output. If labels
parameter 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 = 5000000 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
Generates:
user system total real for: 0.970000 0.000000 0.970000 ( 0.970493) times: 0.990000 0.000000 0.990000 ( 0.989542) upto: 0.970000 0.000000 0.970000 ( 0.972854) >total: 2.930000 0.000000 2.930000 ( 2.932889) >avg: 0.976667 0.000000 0.976667 ( 0.977630)
Returns the elapsed real time used to execute the given block.
Zlib::GzipReader
wrapper that unzips data
.
Prints the amount of time the supplied block takes to run using the debug UI output.
Get the configuration of the current server.
If there is no current server, this returns the default configuration. See current_server
and DRbServer::make_config.
Get the configuration of the current server.
If there is no current server, this returns the default configuration. See current_server
and DRbServer::make_config.
Get the front object of the current server.
This raises a DRbServerNotFound
error if there is no current server. See current_server
.
Get the front object of the current server.
This raises a DRbServerNotFound
error if there is no current server. See current_server
.
Skips the current file or directory, restarting the loop with the next entry. If the current file is a directory, that directory will not be recursively entered. Meaningful only within the block associated with Find::find
.
See the Find
module documentation for an example.
Skips the current file or directory, restarting the loop with the next entry. If the current file is a directory, that directory will not be recursively entered. Meaningful only within the block associated with Find::find
.
See the Find
module documentation for an example.
URI::extract(str[, schemes][,&blk])
Extracts URIs from a string. If block given, iterates through all matched URIs. Returns nil if block given or array with matches.
require "uri" URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.") # => ["http://foo.example.com/bla", "mailto:test@example.com"]
Raises a TypeError
to prevent cloning.
Returns the singleton instance.
Perform an operation in a block, raising an error if it takes longer than sec
seconds to complete.
sec
Number of seconds to wait for the block to terminate. Any number may be used, including Floats to specify fractional seconds. A value of 0 or nil
will execute the block without any timeout.
klass
Exception
Class
to raise if the block fails to terminate in sec
seconds. Omitting will use the default, Timeout::Error
message
Error
message to raise with Exception
Class
. Omitting will use the default, “execution expired”
Returns the result of the block if the block completed before sec
seconds, otherwise throws an exception, based on the value of klass
.
The exception thrown to terminate the given block cannot be rescued inside the block unless klass
is given explicitly. However, the block can use ensure to prevent the handling of the exception. For that reason, this method cannot be relied on to enforce timeouts for untrusted blocks.
Note that this is both a method of module Timeout
, so you can include Timeout
into your classes so they have a timeout
method, as well as a module method, so you can call it directly as Timeout.timeout()
.
Perform an operation in a block, raising an error if it takes longer than sec
seconds to complete.
sec
Number of seconds to wait for the block to terminate. Any number may be used, including Floats to specify fractional seconds. A value of 0 or nil
will execute the block without any timeout.
klass
Exception
Class
to raise if the block fails to terminate in sec
seconds. Omitting will use the default, Timeout::Error
message
Error
message to raise with Exception
Class
. Omitting will use the default, “execution expired”
Returns the result of the block if the block completed before sec
seconds, otherwise throws an exception, based on the value of klass
.
The exception thrown to terminate the given block cannot be rescued inside the block unless klass
is given explicitly. However, the block can use ensure to prevent the handling of the exception. For that reason, this method cannot be relied on to enforce timeouts for untrusted blocks.
Note that this is both a method of module Timeout
, so you can include Timeout
into your classes so they have a timeout
method, as well as a module method, so you can call it directly as Timeout.timeout()
.
Gets the scheduling priority for specified process, process group, or user. kind indicates the kind of entity to find: one of Process::PRIO_PGRP
, Process::PRIO_USER
, or Process::PRIO_PROCESS
. integer is an id indicating the particular process, process group, or user (an id of 0 means current). Lower priorities are more favorable for scheduling. Not available on all platforms.
Process.getpriority(Process::PRIO_USER, 0) #=> 19 Process.getpriority(Process::PRIO_PROCESS, 0) #=> 19
See Process.getpriority
.
Process.setpriority(Process::PRIO_USER, 0, 19) #=> 0 Process.setpriority(Process::PRIO_PROCESS, 0, 19) #=> 0 Process.getpriority(Process::PRIO_USER, 0) #=> 19 Process.getpriority(Process::PRIO_PROCESS, 0) #=> 19
Returns a Tms
structure (see Process::Tms
) that contains user and system CPU times for this process, and also for children processes.
t = Process.times [ t.utime, t.stime, t.cutime, t.cstime ] #=> [0.0, 0.02, 0.00, 0.00]
Returns the form how EC::Point
data is encoded as ASN.1.
See also point_conversion_form=
.
Sets the form how EC::Point
data is encoded as ASN.1 as defined in X9.62.
format can be one of these:
:compressed
Encoded as z||x, where z is an octet indicating which solution of the equation y is. z will be 0x02 or 0x03.
:uncompressed
Encoded as z||x||y, where z is an octet 0x04.
:hybrid
Encodes as z||x||y, where z is an octet indicating which solution of the equation y is. z will be 0x06 or 0x07.
See the OpenSSL
documentation for EC_GROUP_set_point_conversion_form()
Add file name
with permissions mode
size
bytes long. Yields an IO
to write the file to.