jacob
2014-10-19 15:03:31 +08:00
ruby 的存在感这么低吗
----------
def sum
i,s=0,0
start=Time.now
while i<1000000000
i+=1
s+=i
end
puts "sum of while:#{s},time:#{Time.now-start}"
end
sum()
def sum_of_range
s=0
start=Time.now
digi=1..1000000000
digi.each do |d|
s+=d
end
puts "sum of range:#{s},time:#{Time.now-start}"
end
sum_of_range()
------------------------
sum of while:500000000500000000,time:255.076978
sum of range:500000000500000000,time:343.893392