我有两条文字,利用机械化,打上谷歌指数页。 我假定,Machine会比Ruby望快,但不是。
活动Machine代码费用:0.24suser 0.08s system 2% cpu 12.682 Total"
法文版编码费用:0.22suser 0.08s system 5% cpu 5.167 Total "
我以错误的方式使用事件吗?
活动:
require rubygems
require mechanize
require eventmachine
trap("INT") {EM.stop}
EM.run do
num = 0
operation = proc {
agent = Mechanize.new
sleep 1
agent.get("http://google.com").body.to_s.size
}
callback = proc { |result|
sleep 1
puts result
num+=1
EM.stop if num == 9
}
10.times do
EventMachine.defer operation, callback
end
end
页: 1
require rubygems
require mechanize
threads = []
10.times do
threads << Thread.new do
agent = Mechanize.new
sleep 1
puts agent.get("http://google.com").body.to_s.size
sleep 1
end
end
threads.each do |aThread|
aThread.join
end