CommonLISP実装を比較する
単純な計算を比較してCommonLISP実装を比較してみる.
とはいってもCommonLISPにはいろいろコンパイルオプションがあるので,単純に比較するのはできないのだけど,あくまで参考程度ということで..
比較したのは以下のフィボナッシ数列とアッカーマン関数の再帰関数である.
#リスト処理もやっていない関数で比較にならないって?あくまで参考程度だから..
(defun fib (x) (cond *1 (fib (- x 2))))) ) (defun ack (M N) (cond *2 *3 (t (ack (- M 1) (ack M (- N 1))))) )
マシンはMacPro(2x2.66G Dual-Core Intel Xeon,メモリー1G).
- AllegroCommonLISP 8.0
Optimization settings: safety 1, space 1, speed 1, debug 2
です.
CL-USER(8): (time (fib 30)) ; cpu time (non-gc) 10,920 msec user, 20 msec system ; cpu time (gc) 4,880 msec user, 30 msec system ; cpu time (total) 15,800 msec user, 50 msec system ; real time 15,854 msec ; space allocation: ; 66,284,964 cons cells, -934,298,656 other bytes, 0 static bytes 1346269 CL-USER(10): (time (ack 3 7)) ; cpu time (non-gc) 3,230 msec user, 30 msec system ; cpu time (gc) 14,580 msec user, 0 msec system ; cpu time (total) 17,810 msec user, 30 msec system ; real time 17,844 msec ; space allocation: ; 22,900,810 cons cells, 893,934,112 other bytes, 39,488 static bytes 1021
(fib 30)が約15秒
(ack 3 7)が約17秒
コンパイルオプションを結構いじらないといけないんでしょうか..
- SBCL 1.02
* (time (fib 30)) Evaluation took: 0.058 seconds of real time 0.057549 seconds of user run time 9.e-5 seconds of system run time 0 calls to %EVAL 0 page faults and 8,192 bytes consed. 1346269 * (time (fib 40)) Evaluation took: 7.516 seconds of real time 7.515032 seconds of user run time 0.001482 seconds of system run time 0 calls to %EVAL 0 page faults and 0 bytes consed. 165580141 * (time (ack 3 7)) Evaluation took: 0.012 seconds of real time 0.011678 seconds of user run time 5.5e-5 seconds of system run time 0 calls to %EVAL 0 page faults and 0 bytes consed. 1021 * (time (ack 3 9)) Evaluation took: 0.189 seconds of real time 0.188628 seconds of user run time 1.76e-4 seconds of system run time 0 calls to %EVAL 0 page faults and 0 bytes consed. 4093
(fib 30)は0.058秒,(fib 40)は7.5秒
(ack 3 7)は0.012秒,(ack 3 9)は0.189秒
結果としては,デフォルト値ではsbclの圧勝ということになりますが,コンパイルオプションの調整でどうなりますでしょうか..