Speeding Up Your Python Code
maxburstein.com
maxburstein.com
Not only is it slightly faster but you also avoid storing
the entire list in memory!
Actually that won't help when you need a big list and need to store it in memory. Python is really akward with this kind of scenario.
Doing calkulations with Maps of Lists is definitiv (extremly) faster in the JVM, C++ whatever. Python is good however some use cases are definitv not in favor of Python. I mean some could drop to C/C++ for that and pass Pointers around so not the biggest problem. def generate(num):
for i in xrange(num):
yield random.randrange(10)
def create_list(num):
return [random.randrange(10) for i in xrange(num)]
Also worth noting that functional programming in Python (e.g. inlining loops) is often faster. from future_builtins import map
import itertools
def generate(num):
return map(random.randrange, itertools.repeat(10, num))