るりまサーチ

最速Rubyリファレンスマニュアル検索!
77件ヒット [1-77件を表示] (0.072秒)

別のキーワード

  1. _builtin times
  2. integer times
  3. process times
  4. times _builtin

ライブラリ

モジュール

キーワード

検索結果

Process.#times -> Process::Tms (18102.0)

自身のプロセスとその子プロセスが消費したユーザ/システム CPU 時間の積算を Process::Tms オブジェクトで返します。 時間の単位は秒で、浮動小数点数で与えられます。

自身のプロセスとその子プロセスが消費したユーザ/システム CPU 時間の積算を
Process::Tms オブジェクトで返します。
時間の単位は秒で、浮動小数点数で与えられます。

@raise NotImplementedError メソッドが現在のプラットフォームで実装されていない場合に発生します。

@see Process::Tms

Benchmark.#bm(label_width = 0, *labels) {|rep| ... } -> [Benchmark::Tms] (43.0)

Benchmark.#benchmark メソッドの引数を簡略化したものです。

...指定します。

//emlist[][ruby]{
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

#=>
#
# user system total real
# 1.033333 0.016667 1....
...or 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

#=>
# user system total real
# for: 1.050000 0.000000 1.050000 ( 0.503462)
# times: 1.533333 0.016667 1.550000 ( 0....
...}
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

#=>
# user system total real
# for: 0.001467 0.004727 0.006194 ( 0.006193)
# times: 0.003814 0....

Process.#clock_gettime(clock_id, unit=:float_second) -> Float | Integer (31.0)

POSIX の clock_gettime() 関数の時間を返します。

...れかで指定します。
サポートされている定数は OS やバージョンに依存します。

: Process::CLOCK_REALTIME
S
USv2 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0, OpenBSD 2.1, macOS 10.12
: Process::CLOCK_MONOTONIC
SUSv3 to 4, Linux 2.5.63, FreeBSD 3.0, NetBS...
...:GETTIMEOFDAY_BASED_CLOCK_REALTIME と定義されています。

CLOCK_REALTIME のエミュレーション:

: :GETTIMEOFDAY_BASED_CLOCK_REALTIME
S
US で定義されている gettimeofday() を使います。 (しかし SUSv4 で obsoleted になっています)
精度は1マイクロ秒です...
...可能な mach_absolute_time() を使います。
精度は CPU に依存します。
: :TIMES_BASED_CLOCK_MONOTONIC
POSIX で定義されている times() の結果を使います。
POSIX では「times() は過去のある時点 (例えばシステムの起動時刻) からの経過クロッ...

Benchmark.#benchmark(caption = "", label_width = nil, fmtstr = nil, *labels) {|rep| ...} -> [Benchmark::Tms] (19.0)

Benchmark::Report オブジェクトを生成し、それを引数として与えられたブロックを実行します。

...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

#=>
#
# user system total real
# for: 1.016667 0.016667 1.033333 ( 0.485749)
# times: 1.450000 0.016667...

Benchmark.#measure(label = "") { ... } -> Benchmark::Tms (17.0)

与えられたブロックを実行して、経過した時間を Process.#times で計り、 Benchmark::Tms オブジェクトを生成して返します。

...与えられたブロックを実行して、経過した時間を Process.#times で計り、
Benchmark::Tms オブジェクトを生成して返します。

Benchmark::Tms オブジェクトには to_s が定義されているので、
基本的には以下のように使います。

//emlist[]...

絞り込み条件を変える

Kernel.#at_exit { ... } -> Proc (7.0)

与えられたブロックをインタプリタ終了時に実行します。

...
spec/terminateも参照してください。

@return 登録した処理を Proc オブジェクトで返します。

//emlist[例][ruby]{
3.times do |i|
at_exit{puts "at_exit#{i}"}
end
END{puts "END"}
at_exit{puts "at_exit"}
puts "main_end"

#=> main_end
# at_exit
# END
# at_exit2
#...

Process.#waitall -> [[Integer, Process::Status]] (7.0)

全ての子プロセスが終了するのを待ちます。 終了した子プロセスの pid と終了ステータス (Process::Status) の配列の配列を返します。 子プロセスがいない状態でこのメソッドを呼び出すと空の配列を返します。

...空の配列を返します。

$? には最後に終了した子プロセスの Process::Status オブジェクトが設定されます。

2.times {|n|
Process.fork() { exit n }
}
p Process.waitall
#=> :Status: pid=2766,exited(1)>], [2765, #<Process::Status: pid=2765,exited(1...