Skip to content

Instantly share code, notes, and snippets.

@x
Created July 30, 2014 18:29
Show Gist options
  • Select an option

  • Save x/86892f50894cc2e46602 to your computer and use it in GitHub Desktop.

Select an option

Save x/86892f50894cc2e46602 to your computer and use it in GitHub Desktop.
Named Tuple vs Dict Vs Tuple
$ python -m timeit -s 'from collections import namedtuple; NT = namedtuple("NT", "a"); nt = NT(1)' 'nt.a'
10000000 loops, best of 3: 0.138 usec per loop
/U/d/chartbeat(dev)(master)$ python -m timeit -s 'd = (1, )' 'd[0]'
10000000 loops, best of 3: 0.0409 usec per loop
/U/d/chartbeat(dev)(master)$ python -m timeit -s 'd = {"a": 1}' 'd["a"]'
10000000 loops, best of 3: 0.0358 usec per loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment