Setup ===== The worker script has lines like this:: hosts = [] for i in range(NUM_HOSTS): hosts.append(Host("host%06d" % i)) inventory = Inventory(host_list='./big_inventory', loader=loader, variable_manager=var_manager) hosts = inventory.get_hosts()[:] to test how fast we run with inventory in the loop, the inventory section should be invoked last. to test how fast we run with the generated hosts in the loop, the inventory section should be first (so that the generated hosts overwrite the hosts var). Leave both section in the code and uncommented so we are only testing the difference in running the loop, not in setup. Gather profile data =================== Invoke the script like this:: python -m cProfile -o inventory-worker.prof worker.py Then switch which section is creating the hosts var used in the loop as described in setup then run again and output the profiling data to another file:: python -m cProfile -o hosts-worker.prof worker.py There's many thing you can do with the generated profile files. Turn them into a call graph in dot format:: yum install gprof2dot -y gprof2dot -f pstats hosts-worker.prof | dot -Tpng -o hosts-worker.png gprof2dot -f pstats inventory-worker.prof | dot -Tpng -o inventory-worker.png View sorted stats in list form:: python -m pstats hosts-worker.prof hosts-worker.prof% sort cumtime hosts-worker.prof% stats 20 Read the profile documentation for more info: https://docs.python.org/2/library/profile.html