I\'m optimizing some code whose main bottleneck is running through and accessing a very large list of struct-like objects. Currently I\'m using namedtuples, for readability
A couple points and ideas:
You're timing accessing the same index many times in a row. Your actual program probably uses random or linear access, which will have different behavior. In particular, there will be more CPU cache misses. You might get slightly different results using your actual program.
OrderedDictionary is written as a wrapper around dict
, ergo it will be slower than dict
. That's a non-solution.
Have you tried both new-style and old-style classes? (new-style classes inherit from object
; old-style classes do not)
Have you tried using psyco or Unladen Swallow? (2020 Update - these two projects are dead)
Does your inner loop to modify the data or just access it? It might be possible to transform the data into the most efficient possible form before entering the loop, but use the most convenient form elsewhere in the program.