Here is the code from a local discussion group
# foo.nim
import nimpy
proc foo(): seq[array[3,int]]{.exportpy.}=
var a:seq[array[3,int]]
for i in 1..10000000:
a.add([i,i*2,0])
return a
Run
and
# a.py
import time, foo
n=time.time()
that=foo.foo()
print(time.time()-n)
old=time.time()
def test(num):
a=[]
for i in range(num):
temp=[i,i*2,0]
a.append(temp)
return a
oh=test(10000000)
print(time.time()-old)
Run
when I compile the foo.nim with latest-cloned-and-built nim on Win7 64bits( Nim
Compiler Version 0.20.99 [Windows: amd64] Compiled at 2019-06-10) in
MSYS2+MINGW with nim c -d:release --threads:on --app:lib --out:foo.pyd foo then
R:\>e:\prg\py\Anaconda3_64\python.exe a.py
8.30347490310669
10.290588617324829
R:\>r:\python-2.7.16.amd64\python.exe a.py
13.0490000248
21.8800001144
Run
shows that nimpy runs faster than pure python which is expected
however if I compile the python module with nim c -d:release --threads:on
--opt:speed --app:lib --out:foo.pyd foo then
R:\>e:\prg\py\Anaconda3_64\python.exe a.py
17.50800108909607
17.381994247436523
R:\>r:\python-2.7.16.amd64\python.exe a.py
17.4839999676
15.9549999237
Run
it is funny that \--opt:speed slow down the code! What is the problem?