Skip to content

Instantly share code, notes, and snippets.

@zachwill
Created September 2, 2011 01:53
Show Gist options
  • Save zachwill/1187761 to your computer and use it in GitHub Desktop.
Save zachwill/1187761 to your computer and use it in GitHub Desktop.
"""Just showing off timeit to tell the difference between operations."""
from timeit import Timer
# We'll run each one a thousand times.
print Timer("[0] * 7000").timeit(1000)
print Timer("bytearray(7000)").timeit(1000)
# Just a JSON example.
print Timer("""json.loads('{"a": {"b": {"c": "d"}}}')""",
"import json").timeit(1000)
print Timer("""json.loads('{"a": {"b": {"c": "d"}}}')""",
"import simplejson as json").timeit(1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment