3 ms·
It runs at 1/10 speed because it's interpreted bytecode, and it allocates a new PyInt object for each number in the loop. You can get it back close to native s
by ProblemFactory 11y ago
It runs at 1/10 speed because it's interpreted bytecode, and it allocates a new PyInt object for each number in the loop.
You can get it back close to native speed by adding a type annotation and compiling the python file with Cython: http://docs.cython.org/src/userguide/language_basics.html#integer-for-loops http://docs.cython.org/src/userguide/language_basics.html#in...
def f(NUMBER):
cdef int i
for i in range(NUMBER):
pass
- andreasvc 11y agoNot just close to native speed, this will get you the exact same C code for the inner loop.