If you are on a Unix machine, you can always open topin a new terminal and then observe the use of% when starting your python program. In addition, there are some third-party libraries that you can use.
Here is one: Benchmark
Examples (taken from the [py package] index ( https://pypi.python.org/pypi/Benchmarker/4.0.1 ):
Program:
from benchmarker import Benchmarker
with Benchmarker(1000*1000, width=20) as bench:
s1, s2, s3, s4, s5 = "Haruhi", "Mikuru", "Yuki", "Itsuki", "Kyon"
@bench(None) ## empty loop
def _(bm):
for i in bm:
pass
@bench("join")
def _(bm):
for i in bm:
sos = ''.join((s1, s2, s3, s4, s5))
@bench("concat")
def _(bm):
for i in bm:
sos = s1 + s2 + s3 + s4 + s5
@bench("format")
def _(bm):
for i in bm:
sos = '%s%s%s%s%s' % (s1, s2, s3, s4, s5)
:
$ python example.py -h
$ python example.py -o result.json
#
#
#
#
#
#
#
#
(Empty) 0.0236 0.0200 0.0200 0.0000
join 0.2779 0.2800 0.2800 0.0000
concat 0.3792 0.3800 0.3800 0.0000
format 0.4233 0.4300 0.4300 0.0000
#
join 0.2779 (100.0) ********************
concat 0.3792 ( 73.3) ***************
format 0.4233 ( 65.6) *************
#
[01] join 0.2779 100.0 136.5 152.3
[02] concat 0.3792 73.3 100.0 111.6
[03] format 0.4233 65.6 89.6 100.0