|
|
|
|
|
by Hamuko
856 days ago
|
|
Yeah, it's not great with long strings. f-strings seem to be great just about always though. Highly recommend. $ python3.12 -m timeit -s 'import string' -s 'x = string.printable * 50' 'f"Welcome to {x}."'
2000000 loops, best of 5: 106 nsec per loop
$ python3.12 -m timeit -s 'import string' -s 'x = string.printable * 50' '"Welcome to {}.".format(x)'
2000000 loops, best of 5: 200 nsec per loop
$ python3.12 -m timeit -s 'import string' -s 'x = string.printable * 50' '"Welcome to %s." % x'
2000000 loops, best of 5: 169 nsec per loop
$ python3.12 -m timeit -s 'import string' -s 'x = string.printable * 50' '"Welcome to " + str(x) + "."'
1000000 loops, best of 5: 214 nsec per loop
$ python3.12 -m timeit -s 'import string' -s 'x = string.printable * 50' '"Welcome to " + x + "."'
1000000 loops, best of 5: 198 nsec per loop
len(string.printable * 50) = 5000 |
|