Last active
April 12, 2020 04:00
-
-
Save 0atman/373573e1f91758263fc0ced5a5166f7b to your computer and use it in GitHub Desktop.
IMO Nim is an advanced, complied superset of python
This file contains 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 characters
import math, strformat, times | |
func fib(n: int): int = | |
if n <= 2: | |
return 1 | |
else: | |
return fib(n - 1) + fib(n - 2) | |
when isMainModule: | |
let x = 47 | |
let start = epochTime() | |
let res = fib(x) | |
let elapsed = epochtime() - start | |
echo(&"Nim Computed fib({x})={res} in {elapsed} seconds") |
This file contains 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 characters
import time | |
def fib(n: int) -> int: | |
if n <= 2: | |
return 1 | |
else: | |
return fib(n - 1) + fib(n - 2) | |
if __name__ == "__main__": | |
x = 47 | |
start = time.time() | |
res = fib(x) | |
elapsed = time.time() - start | |
print(f"Py3 Computed fib({x})={res} in {elapsed} seconds") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code taken from https://robert-mcdermott.gitlab.io/posts/speeding-up-python-with-nim/
Python ran in 504.55 seconds
Nim ran in 4.63 seconds, same speed as C, and faster than any other language he tested:
I'd imagine rust is equivalent to the nim and c speed.