diff --git a/examples/simple_examples.py b/examples/simple_examples.py index b84cf212..8b29b06c 100644 --- a/examples/simple_examples.py +++ b/examples/simple_examples.py @@ -1,9 +1,41 @@ """ -Simple tqdm examples and profiling +# 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/ +from progressbar.progressbar import ProgressBar +for i in ProgressBar()(_range(int(1e8))): + pass """ from time import sleep from timeit import timeit +import re # Simple demo from tqdm import trange @@ -11,23 +43,7 @@ for i in trange(16, leave=True): sleep(0.1) # Profiling/overhead tests -stmts = ( - # Benchmark - 'for i in _range(int(1e8)):\n\tpass', - # Basic demo - 'import tqdm\nfor i in tqdm.trange(int(1e8)):\n\tpass', - # Some decorations - 'import tqdm\nfor i in tqdm.trange(int(1e8), miniters=int(1e6),' - ' ascii=True, desc="cool", dynamic_ncols=True):\n\tpass', - # Nested bars - 'from tqdm import trange\nfor i in trange(10):\n\t' - 'for j in trange(int(1e7), leave=False, unit_scale=True):\n\t\tpass', - # Experimental GUI demo - 'import tqdm\nfor i in tqdm.tgrange(int(1e8)):\n\tpass', - # Comparison to https://code.google.com/p/python-progressbar/ - 'from progressbar.progressbar import ProgressBar\n' - 'for i in ProgressBar()(_range(int(1e8))):\n\tpass') - +stmts = filter(None, re.split(r'\n\s*#.*?\n', __doc__)) for s in stmts: print(s.replace('import tqdm\n', '')) print(timeit(stmt='try:\n\t_range = xrange'