Skip to content

Instantly share code, notes, and snippets.

@karlcow
Created June 8, 2017 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlcow/bbc10d9ff6eeb6649f99eba400a10814 to your computer and use it in GitHub Desktop.
Save karlcow/bbc10d9ff6eeb6649f99eba400a10814 to your computer and use it in GitHub Desktop.
dict and optimizations

It is faster to create the dict with the first value than creating and adding.

python -mtimeit "issue = {}; issue['action'] = 'opened'; issue['title'] = 'foo'"
10000000 loops, best of 3: 0.135 usec per loop

python -mtimeit "issue = {'action': 'opened'}; issue['title'] = 'foo'" 
10000000 loops, best of 3: 0.111 usec per loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment