
Speeding up Python with Nim - mcdermott
https://robert-mcdermott.gitlab.io/posts/speeding-up-python-with-nim/
======
ckot
Hmm. this didn't render the newlines in my code, and markdown doesn't seem to
be supported. bummer.

Really cool! It seems to be comparable and perhaps even faster than cython!

I happened to be in an Ipython shell and didn't see anyway to do this with
nim, but you can probably get a good _approximate_ of the speedup with nim in
Ipython/Jupyter by doing a quick:

[1] %load_ext Cython

[2] %%cython ``` cpdef long cyfib(int n): if n <= 2: return 1 else: return
cyfib(n - 1) + cyfib(n - 2) ```

[3] start=time.time(); x = cyfib(47); end=time.time(); print(x); print(end-
start)

2971215073 5.558561325073242

Nice choice of 47! I had to change the cython function's return time to long
to prevent overflow. Something you don't need to do in nim

------
etherway
Nice writing. Using python as a 'glue' lang and nim as a 'core' lang makes a
lot of sense. Will give it a try for my next project.

------
jaco8
You also can use lots of python functions directly in nim too. Do this in nim:

import nimpy; let datetime = pyImport("datetime"); echo
datetime.datetime.now(); let pysys = pyImport("sys") ; echo pysys.version;

It is really cool.

------
matusf
The complexity is of recursive implementation of fibonacci is O(golden ratio ^
n). If it was O(n ^ 2) it would run under 0.1s.

By the way, the nimpy looks cool. Thanks for sharing.

------
jblindsay
This was an excellent read. I'll have to take a deeper look at the NimPy
project that was mentioned in the article. Thanks for sharing.

