3 ms·
I failed to get numba installed on a Raspberry Pi 2, and I'd been wanting to try Nim, which turned out to be easy to compile on the RPi running Ubuntu. nim -
by ycnews 11y ago
I failed to get numba installed on a Raspberry Pi 2, and I'd been wanting to try Nim, which turned out to be easy to compile on the RPi running Ubuntu.
nim -r -d:release c rw_fibn.nim
...
Hint: operation successful (12152 lines compiled; 2.632 sec total; 8.870MB; Release Build) [SuccessX]
/home/rw/git/Nim/examples/rw_fibn
Result = 8944394323791464
elapsed time: 5.376946926116943
My first try at translating Python to Nim:
$ cat rw_fibn.nim
import times
proc fibn(reps: int64, num: int): int64 =
var z: int64
for r in 1..reps:
var
p1, p2: int64 = 1
rnum: int = num - 2
for i in 1..rnum:
z = p1 + p2
p2 = p1
p1 = z
return z
var start: float = times.epochTime()
var res = fibn(10_000_000, 78)
var finish: float = times.epochTime()
echo("Result = ", res)
echo("elapsed time: ", finish - start)