Pythonスレに貼られていた煽りコピペ
Pythonオワタ・・・orz
俺もう乗り換えるわRunning the snippets above, I got the following results:
Python 2.5.1: 31.507s
Ruby 1.9.0: 11.934sThe Ruby code:
ソースは長いので略。*1
折角どっちも入っているのだから、と試してみた。
python fib.py 61.28s user 0.26s system 93% cpu 1:05.94 total
ruby fib.rb 164.47s user 0.43s system 97% cpu 2:49.17 total
おんぼろでの実証、複数回行って*いない*等、データとしては色々アレだけど。
で、ついでだからOCamlでも書いた。
let rec fib n = match n with 0|1 -> n | _ -> fib(n-1)+fib(n-2) in let rec loop n = if n=36 then n else let d = (Printf.printf "n=%d => %d\n" n (fib n)) in (loop (n+1)) in (loop 0)
なお、当然だが、見た目でのアルゴリズムによる高速化は行っていない。*2
で、その結果。
ocaml fib.ml 6.58s user 0.05s system 91% cpu 7.220 total
…おk、OCaml最速でFAだね。
…こんなに違って良いのか?