4 ms·
Why isn't Python using the more efficient code automatically when you write '(a * b) % n'? Seems like something that is the language's job.
by chrisseaton 5y ago
Why isn't Python using the more efficient code automatically when you write '(a * b) % n'? Seems like something that is the language's job.
- karatinversion 5y agoPython allows for overloading these operators, and has dynamic types, so cannot produce the more efficient byte code on load. Most python interpreters also don't have JIT compilers that could do the optimization on the fly.
- chrisseaton 5y agoHmm.. when you compile to byte code you could emit a single POW_MOD instruction, and then dispatch to the more efficient code if both methods remain un-redefined, or call the full methods if one or more has been redefined.