Ruby 初心者スレッド Part 21
at TECH
343:デフォルトの名無しさん
08/08/29 23:42:39
require 'open-uri'
require 'benchmark'
uris = %w(URLリンク(www.yahoo.co.jp) URLリンク(pc11.2ch.net) URLリンク(www.yahoo.com)).map{|e| URI(e)}
Benchmark.bm(2) do |x|
x.report{
uris.each do |uri|
uri.read
end
}
end
sleep 2
Benchmark.bm(2) do |x|
x.report{
threads = Array.new
uris.each do |uri|
threads.push(Thread.new { uri.read })
end
threads.each{|thread| thread.join}
}
end
# 結果
user system total real
1.150000 0.080000 1.230000 ( 2.655373)
user system total real
1.210000 0.060000 1.270000 ( 1.583636)
次ページ続きを表示1を表示最新レス表示スレッドの検索類似スレ一覧話題のニュースおまかせリスト▼オプションを表示暇つぶし2ch
5494日前に更新/211 KB
担当:undef