我想知道是不是很难检查?
▶ Benchmark.measure { 3.times { |i|
Thread.new { puts Benchmark.measure { sleep i }.inspect }
} }
#⇒ #<Benchmark::Tms:0x000000018c2818 @label="", @real=8.5858e-05, @cstime=0.0, @cutime=0.0, @stime=0.0, @utime=0.0, @total=0.0>
#⇒ #<Benchmark::Tms:0x000000018c3ab0 @cstime=0.0, @cutime=0.0, @label="", @real=0.000118425, @stime=0.0, @total=0.0, @utime=0.0>
#⇒ #<Benchmark::Tms:0x0000000183cc40 @label="", @real=1.000119122, @cstime=0.0, @cutime=0.0, @stime=0.0, @utime=0.0, @total=0.0>
#⇒ #<Benchmark::Tms:0x0000000183c7e0 @label="", @real=2.000088775, @cstime=0.0, @cutime=0.0, @stime=0.0, @utime=0.0, @total=0.0>
第二行显然是周围的总数。
好的,这是一个唤醒线程的示例(最后是总数):
▶ Benchmark.measure { 3.times { |i| Thread.new { puts Benchmark.measure { (i * 100_000_000).times { 2000 << 2 } }.inspect } } }
#⇒ #<Benchmark::Tms:0x000000016c6438 @label="", @real=2.377e-06, @cstime=0.0, @cutime=0.0, @stime=0.0, @utime=0.0, @total=0.0>
#⇒ #<Benchmark::Tms:0x000000016c5420 @label="", @real=9.034328202, @cstime=0.0, @cutime=0.0, @stime=0.0, @utime=9.040000000000001, @total=9.040000000000001>
#⇒ #<Benchmark::Tms:0x000000016c4a98 @label="", @real=13.769757073, @cstime=0.0, @cutime=0.0, @stime=0.010000000000000009, @utime=13.77, @total=13.78>
#⇒ #<Benchmark::Tms:0x000000016c6bb8 @cstime=0.0, @cutime=0.0, @label="", @real=5.1321e-05, @stime=0.0, @total=0.0, @utime=0.0>