From 9fc5a164345073e0918cb0f0f5c1d6a8056ce18f Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 26 Nov 2015 10:08:41 +0000 Subject: [PATCH] neater examples with memory overhead reduced to negligible --- examples/simple_examples.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/simple_examples.py b/examples/simple_examples.py index eec41035..4ac12e53 100644 --- a/examples/simple_examples.py +++ b/examples/simple_examples.py @@ -13,18 +13,20 @@ for i in trange(16, leave=True): # Profiling/overhead tests stmts = ( # Benchmark - '[0 for i in xrange(int(1e8))]', + 'for i in _range(int(1e8)):\n\tpass', # Basic demo - 'import tqdm; [0 for i in tqdm.trange(int(1e8))]', + 'import tqdm\nfor i in tqdm.trange(int(1e8)):\n\tpass', # Some decorations - 'import tqdm; [0 for i in tqdm.trange(int(1e8), miniters=int(1e6),' - ' ascii=True, desc="cool", dynamic_ncols=True)]', + 'import tqdm\nfor i in tqdm.trange(int(1e8), miniters=int(1e6),' + ' ascii=True, desc="cool", dynamic_ncols=True):\n\tpass', # Experimental GUI demo - 'import tqdm; [0 for i in tqdm.tgrange(int(1e8))]', + '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;' - ' [0 for i in ProgressBar()(xrange(int(1e8)))]') + 'from progressbar.progressbar import ProgressBar\n' + 'for i in ProgressBar()(_range(int(1e8))):\n\tpass') for s in stmts: - print(s) - print(timeit(stmt=s, number=1), 'seconds') + print(s.replace('import tqdm\n', '')) + print(timeit(stmt='try:\n\t_range = xrange' + '\nexcept:\n\t_range = range\n' + s, number=1), + 'seconds')