Created
March 28, 2018 14:35
-
-
Save sakal/722ce2ef8bfda8235e1b5009e888bc65 to your computer and use it in GitHub Desktop.
py3.6 string format vs concat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> $ python3.6 [±claymore-115 ✓▴] | |
Python 3.6.5rc1 (default, Mar 14 2018, 06:54:23) | |
[GCC 7.3.0] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import timeit | |
>>> def d1(a, b): | |
... return a + '_' + b | |
... | |
>>> def d2(a, b): | |
... return '%s_%s' % (a, b) | |
... | |
>>> def d3(a, b): | |
... return '{}_{}'.format(a, b) | |
... | |
>>> timeit.timeit('d1("asd", "qwe")', setup='from __main__ import d1', number=1000000) | |
0.213849229999596 | |
>>> timeit.timeit('d2("asd", "qwe")', setup='from __main__ import d2', number=1000000) | |
0.2879158160003499 | |
>>> timeit.timeit('d3("asd", "qwe")', setup='from __main__ import d3', number=1000000) | |
0.3701504420000674 | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment