Hacker News new | past | comments | ask | show | jobs | submit login

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#in...

    def f(NUMBER):
        cdef int i
        for i in range(NUMBER):
            pass



Not just close to native speed, this will get you the exact same C code for the inner loop.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: