18
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Common Lispで書く→はやい

Last updated at Posted at 2015-11-06

#発端
RubyからGoの関数をつかう → はやい

##関連
RubyからRustの関数をつかう → はやい
Crystalで書く → はやい

上記記事への便乗です。

#条件
Arch Linux on Windows7(VirtualBox)で検証しています。

$ uname -a
Linux ArchLinux 4.2.5-1-ARCH #1 SMP PREEMPT Tue Oct 27 08:13:28 CET 2015 x86_64 GNU/Linux
$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
$ sbcl --version
SBCL 1.2.16


#内容

fib.rb
def fib(n)
  return n if n <= 1
  fib(n - 1) + fib(n - 2)
end

puts fib(40)
fib.lisp
(defun fib (n)
    (if (<= n 1)
        n
        (+ (fib (- n 1)) (fib (- n 2)))))

(print (fib 40))

#結果

$ time ruby fib.rb
102334155

real    0m19.350s
user    0m19.063s
sys     0m0.020s


$ time sbcl --script fib.lisp

102334155
real    0m4.836s
user    0m4.833s
sys     0m0.000s

Common Lispの方がRubyの4倍ほど速いですね。

##コンパイルしてみる

$ sbcl

*(compile-file "fib.lisp")
NIL
*(quit)

$ time sbcl --script fib.fasl

102334155
real    0m4.787s
user    0m4.780s
sys     0m0.007s

あんまり変わらないですね。

#おわり
共有ライブラリの作り方とか分からないので、どなたかお願いします(丸投げ)。

#おまけ

$ clisp --version
GNU CLISP 2.49 (2010-07-07) (built on foutrelis)
...
(省略)
...

$ time clisp fib.lisp

102334155

real    3m7.812s
user    3m7.807s
sys     0m0.003s

CLISP遅い...?

#追記
Clozure CL

$ wget ftp://ftp.clozure.com/pub/release/1.10/ccl-1.10-linuxx86.tar.gz
$ tar zxvf ccl-1.10-linuxx86.tar.gz
$ cp ccl/lx86cl64* ~/bin //PATHの通ったとこ
$ source ~/.bashrc
$ alias ccl="lx86cl64"
$ time ccl --load fib.lisp --eval '(quit)'
102334155

real    0m1.535s
user    0m1.530s
sys     0m0.003s

Rubyと比べて12倍ほど速くなりました!

18
14
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?