ぱいおつ

require 'mathn'
require 'benchmark'

puts Benchmark::CAPTION
puts Benchmark.measure{
n = 1
tmp0 = 1
tmp1 = "minus"

150000.times do
if tmp1 == "minus" then
n += 2
tmp0 = tmp0 - (1/n).to_f
tmp1 = "plus"
else
n += 2
tmp0 = tmp0 + (1/n).to_f
tmp1 = "minus"
end
end
p 4 * tmp0
}

0 コメント: