てきとう

てきとう

どうでもいいはなし

Pythonスレに貼られていた煽りコピペ

Pythonオワタ・・・orz
俺もう乗り換えるわ

Running the snippets above, I got the following results:

Python 2.5.1:   31.507s
Ruby 1.9.0:    11.934s

The 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だね。
…こんなに違って良いのか?

*1:一応アドレス→http://pc11.2ch.net/test/read.cgi/tech/1196426978/11

*2:全体的にOCaml仕様にはなっているが。Rubyでもtimes使ってるから特に問題ではないと思う