Skip to content

Instantly share code, notes, and snippets.

@jeamland
Created November 12, 2012 04:46
Show Gist options
  • Save jeamland/4057571 to your computer and use it in GitHub Desktop.
Save jeamland/4057571 to your computer and use it in GitHub Desktop.
> python -m timeit 'str("wombles are small") + ";"'
1000000 loops, best of 3: 0.309 usec per loop
> python -m timeit '"%s;" % "wombles are small"'
10000000 loops, best of 3: 0.0344 usec per loop
> python -m timeit '"{};".format("wombles are small")'
1000000 loops, best of 3: 0.374 usec per loop
@schinckel
Copy link

python -m timeit '"wombles are small" + ";" + ";"'
10000000 loops, best of 3: 0.0313 usec per loop
python -m timeit '"%s%s;" % ("wombles are small", ";")'
1000000 loops, best of 3: 0.212 usec per loop
python -m timeit '"%(a)s%(b)s;" % {"a":"wombles are small", "b":";"}'
1000000 loops, best of 3: 0.429 usec per loop
python -m timeit '"{}{};".format("wombles are small", ";")'
1000000 loops, best of 3: 0.45 usec per loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment