20
20

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.

Crystalで書く → はやい

Last updated at Posted at 2015-11-06

RubyからGoの関数をつかう → はやいの便乗。

フィボナッチ数計算のコードをそのまんま、拡張子だけcrに変えて試してみた。
(桁はちょっと少なめで検証)

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

puts fib(40) #50だとrubyの実行時間がかかりすぎたため

で、結果。

(ruby: 2.2.2, crystal: 0.9.1)

ruby

$ time ruby fib.rb
102334155

real  0m17.136s
user  0m17.050s
sys 0m0.063s
crystal
$ time crystal fib.cr
102334155

real  0m1.960s
user  0m0.990s
sys 0m0.400s
ビルド済みcrystal
$ crystal build fib.cr --release
$ time ./fib
102334155

real  0m0.646s
user  0m0.639s
sys 0m0.004s

go(1.5.1)の

go
$ time go run fib.go
102334155

real	0m1.386s
user	0m1.216s
sys	0m0.116s
ビルド済みGo
$ time ./fib
102334155

real	0m0.765s
user	0m0.755s
sys	0m0.006s

と比較すると大差ないレベル。

追記

crystalでのShared Library作成についてはまだ検討中らしい。
Add the ability to create a dynamic library

20
20
0

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
20
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?