How to make Python run as fast (or faster) than Julia

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Feb 26 19:17:10 EST 2018


On Tue, 27 Feb 2018 02:09:53 +1100, Chris Angelico wrote:

> You're still reimplementing the C code in Python, which is inefficient.
> Have you considered going back to the *actual algorithm* and
> implementing that idiomatically in Python? I think you'll find that (a)
> the code is more readable, and (b) the run time is much lower.

Chris, I think this is incredibly optimistic, if not naive. We're talking 
about a PRNG by Marsaglia, so my guess is that the "original algorithm" 
*is* the C code. Or possibly Fortran.

Even if not, even if there is actually a language-neutral algorithm, its 
a PRNG which means its going to be filled with bit-twiddling and number-
crunching operations. Pure Python without a JIT is never going to be 
competitive with C or Fortran for code like that.


-- 
Steve




More information about the Python-list mailing list