Skip to content

Instantly share code, notes, and snippets.

@9thbit
Created October 12, 2011 16:48
Show Gist options
  • Save 9thbit/1281789 to your computer and use it in GitHub Desktop.
Save 9thbit/1281789 to your computer and use it in GitHub Desktop.
Benchmarks for popping from a python list
# Benchmarks for popping from a list
# If you want to always pop the first element of a list, then don't use pop(0)
# Instead reverse the list once and use pop.
python -m timeit "a=range(1000000)" "a.reverse()" "while a: a.pop()"
python -m timeit "a=range(1000000)" "while a: a.pop(0)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment