Skip to content

Instantly share code, notes, and snippets.

@jessicald
jessicald / gist:2861038
Created June 3, 2012 02:34
Class vs. Dictionary; or, An Example of Space-Time Tradeoff

Class vs. Dictionary; or, An Example of Space–Time Tradeoff in Python

Conclusions; or, tl;dr

What wins?

  • struct-like objects, i.e. ones that are largely the same as a C struct instance, win in the memory department.
    • These tests do not try to determine what is best for very large sets of values, however; I direct the reader to http://stackoverflow.com/a/2670191 for an insight into that scenario when using a dictionary.
  • Dictionaries beat out objects in access times.
  • According to Wikipedia, the Python dictionary is highly optimised because it is used internally to implement namespaces. [citation needed]