-
-
Save tsujp/2d454015ec22d8a7a6dcb94f9ee493f5 to your computer and use it in GitHub Desktop.
Revisions
-
s0kil revised this gist
Jun 5, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Fibonacci - Crystal vs OCaml vs Go ## Crystal -
s0kil renamed this gist
Jun 5, 2020 . 1 changed file with 49 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -89,3 +89,52 @@ Runtime: 9.0s Conclusion: 9.1s ``` ## Go Program: `fibonacci.go` ```go package main func fibonacci(n int) int { if n <= 1 { return n } return fibonacci(n-1) + fibonacci(n-2) } func main() { print(fibonacci(46)) } ``` Compile: ```bash $ time go build -o fibonacci-go fibonacci.go real 0m0.122s user 0m0.132s sys 0m0.045s ``` Run: ```bash $ /usr/bin/time -v ./fibonacci-go 1836311903 Command being timed: "./fibonacci-go" User time (seconds): 12.50 Percent of CPU this job got: 100% Maximum resident set size (kbytes): 1244 ``` Result: ```bash Compilation: 0.1s Runtime: 12.5s Conclusion: 12.6s ``` -
s0kil revised this gist
Jun 5, 2020 . 1 changed file with 43 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -44,7 +44,48 @@ Result: ```bash Compilation: 8.2s Runtime: 9.1s Conclusion: 17.3s ``` ## OCaml Program: `fibonacci.ml` ```ocaml let rec fibonacci = function n -> if n < 2 then n else fibonacci (n - 1) + fibonacci (n - 2) ;; print_int (fibonacci(46)) ``` Compile: ```bash $ time ocamlopt -o fibonacci-ml fibonacci.ml real 0m0.082s user 0m0.065s sys 0m0.017s ``` Run: ```bash $ /usr/bin/time -v ./fibonacci-ml 1836311903 Command being timed: "./fibonacci-ml" User time (seconds): 9.02 Percent of CPU this job got: 99% Maximum resident set size (kbytes): 2308 ``` Result: ```bash Compilation: 0.1s Runtime: 9.0s Conclusion: 9.1s ``` -
s0kil revised this gist
Jun 5, 2020 . No changes.There are no files selected for viewing
-
s0kil renamed this gist
Jun 5, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
s0kil revised this gist
Jun 5, 2020 . No changes.There are no files selected for viewing
-
s0kil created this gist
Jun 5, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ # Fibonacci - OCaml vs Crystal ## Crystal Program: `fibonacci.cr` ```crystal def fibonacci(n) return n if n < 2 fibonacci(n - 1) + fibonacci(n - 2) end print fibonacci(46) ``` Clean Cache: ```bash rm -rf ~/.cache/crystal/ ``` Compile: ```bash $ time crystal build --release -o fibonacci-cr fibonacci.cr real 0m8.205s user 0m8.317s sys 0m0.112s ``` Run: ```bash $ /usr/bin/time -v ./fibonacci-cr 1836311903 Command being timed: "./fibonacci-cr" User time (seconds): 9.09 Percent of CPU this job got: 99% Maximum resident set size (kbytes): 3192 ``` Result: ```bash Compilation: 8.2s Runtime: 9.1s Conclusion: 17.3s ```