Skip to content

Instantly share code, notes, and snippets.

@davidwtbuxton
Created February 19, 2015 09:54
Show Gist options
  • Save davidwtbuxton/cc836e21c16d44e87c87 to your computer and use it in GitHub Desktop.
Save davidwtbuxton/cc836e21c16d44e87c87 to your computer and use it in GitHub Desktop.
Python: using dict.update() is a lot slower than just setting a single key.
$ python -m timeit -s 'd = {}' 'd.update({"key": "value"})'
1000000 loops, best of 3: 0.293 usec per loop
$ python -m timeit -s 'd = {}' 'd["key"] = "value"'
10000000 loops, best of 3: 0.0433 usec per loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment