Reducing Python program load times

If you developed an application or model in Python and you want to reduce loading times I recommend:

  1. Search the list of modules that you import
  2. Check the loading time of each module using e.g. the time module in Python
  3. Create modified copies of the modules causing long loading times
  4. Edit the modified copies of those modules by e.g. removing code that you do not need for your model of application, or by refactoring existing code

Example:

t = time.time()

# import random

from random import randint

print(time.time() – t)

Loading random took my application 0.06 seconds. Since I am developing an extensive simulation model, and every component inside my model uses random, I created a modified version of the random module. This reduced loading time by factor 10.