2015-09-14 15:28:07 +00:00
|
|
|
"""
|
|
|
|
Simple tqdm examples and profiling
|
|
|
|
"""
|
|
|
|
|
|
|
|
from time import sleep
|
|
|
|
from timeit import timeit
|
|
|
|
|
|
|
|
# Simple demo
|
|
|
|
from tqdm import trange
|
|
|
|
for i in trange(16, leave=True):
|
|
|
|
sleep(0.1)
|
|
|
|
|
|
|
|
# Profiling/overhead tests
|
2015-09-18 13:30:05 +00:00
|
|
|
stmts = (
|
2015-10-13 22:42:01 +00:00
|
|
|
# Benchmark
|
2015-11-26 10:08:41 +00:00
|
|
|
'for i in _range(int(1e8)):\n\tpass',
|
2015-10-13 22:42:01 +00:00
|
|
|
# Basic demo
|
2015-11-26 10:08:41 +00:00
|
|
|
'import tqdm\nfor i in tqdm.trange(int(1e8)):\n\tpass',
|
2015-10-13 22:42:01 +00:00
|
|
|
# Some decorations
|
2015-11-26 10:08:41 +00:00
|
|
|
'import tqdm\nfor i in tqdm.trange(int(1e8), miniters=int(1e6),'
|
|
|
|
' ascii=True, desc="cool", dynamic_ncols=True):\n\tpass',
|
2015-12-20 20:17:19 +00:00
|
|
|
# Nested bars
|
|
|
|
'from tqdm import trange\nfor i in trange(10):\n\t'
|
2016-01-25 21:25:43 +00:00
|
|
|
'for j in trange(int(1e7), leave=False, unit_scale=True):\n\t\tpass',
|
2015-10-13 22:42:01 +00:00
|
|
|
# Experimental GUI demo
|
2015-11-26 10:08:41 +00:00
|
|
|
'import tqdm\nfor i in tqdm.tgrange(int(1e8)):\n\tpass',
|
2015-10-13 22:42:01 +00:00
|
|
|
# Comparison to https://code.google.com/p/python-progressbar/
|
2015-11-26 10:08:41 +00:00
|
|
|
'from progressbar.progressbar import ProgressBar\n'
|
|
|
|
'for i in ProgressBar()(_range(int(1e8))):\n\tpass')
|
2015-10-29 10:34:47 +00:00
|
|
|
|
2015-09-14 15:28:07 +00:00
|
|
|
for s in stmts:
|
2015-11-26 10:08:41 +00:00
|
|
|
print(s.replace('import tqdm\n', ''))
|
|
|
|
print(timeit(stmt='try:\n\t_range = xrange'
|
|
|
|
'\nexcept:\n\t_range = range\n' + s, number=1),
|
|
|
|
'seconds')
|