2015-09-14 15:28:07 +00:00
|
|
|
"""
|
2016-07-19 07:40:58 +00:00
|
|
|
# Simple tqdm examples and profiling
|
|
|
|
|
|
|
|
# Benchmark
|
|
|
|
for i in _range(int(1e8)):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Basic demo
|
|
|
|
import tqdm
|
|
|
|
for i in tqdm.trange(int(1e8)):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Some decorations
|
|
|
|
import tqdm
|
|
|
|
for i in tqdm.trange(int(1e8), miniters=int(1e6), ascii=True,
|
|
|
|
desc="cool", dynamic_ncols=True):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Nested bars
|
|
|
|
from tqdm import trange
|
|
|
|
for i in trange(10):
|
|
|
|
for j in trange(int(1e7), leave=False, unit_scale=True):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Experimental GUI demo
|
|
|
|
import tqdm
|
|
|
|
for i in tqdm.tgrange(int(1e8)):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Comparison to https://code.google.com/p/python-progressbar/
|
2016-10-30 00:02:19 +00:00
|
|
|
try:
|
|
|
|
from progressbar.progressbar import ProgressBar
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
for i in ProgressBar()(_range(int(1e8))):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Dynamic miniters benchmark
|
|
|
|
from tqdm import trange
|
|
|
|
for i in trange(int(1e8), miniters=None, mininterval=0.1, smoothing=0):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Fixed miniters benchmark
|
|
|
|
from tqdm import trange
|
|
|
|
for i in trange(int(1e8), miniters=4500000, mininterval=0.1, smoothing=0):
|
2016-07-19 07:40:58 +00:00
|
|
|
pass
|
2015-09-14 15:28:07 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
from time import sleep
|
|
|
|
from timeit import timeit
|
2016-07-19 07:40:58 +00:00
|
|
|
import re
|
2015-09-14 15:28:07 +00:00
|
|
|
|
|
|
|
# Simple demo
|
|
|
|
from tqdm import trange
|
2021-01-09 16:50:30 +00:00
|
|
|
for _ in trange(16, leave=True):
|
2015-09-14 15:28:07 +00:00
|
|
|
sleep(0.1)
|
|
|
|
|
|
|
|
# Profiling/overhead tests
|
2016-07-19 07:40:58 +00:00
|
|
|
stmts = filter(None, re.split(r'\n\s*#.*?\n', __doc__))
|
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'
|
2017-08-28 11:42:38 +00:00
|
|
|
'\nexcept:\n\t_range = range\n' + s, number=1), 'seconds')
|