Itertoolsが揺れる理由

zip vs izipまたは「イテレータチップについて他に誰が説明しますか?」



タスクは単純です:[0,1,2,3、...、99999]-> [(0,1)、(2,3)、...、(99998、99999)]、つまり アイテムをペアで選択します。 10万はそれほど多くありません。したがって、各オプションに対してこれを150回行います。

なぜなら テストではサンプリング速度をテストし、結果をリストに入れません-最後の要素のみを返します(すべて計算されます)-参照要素と比較するためだけです。

Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  1. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  2. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  3. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  4. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  5. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  6. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  7. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  8. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  9. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  10. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  11. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  12. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  13. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  14. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  15. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  16. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  17. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  18. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  19. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  20. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  21. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  22. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  23. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  24. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  25. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  26. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  27. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  28. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  29. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  30. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  31. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  32. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  33. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  34. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  35. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  36. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  37. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  38. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  39. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  40. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  41. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  42. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  43. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  44. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  45. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  46. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  47. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  48. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  49. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  50. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  51. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  52. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  53. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  54. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  55. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  56. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  57. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  58. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  59. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  60. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )
  61. Copy Source | Copy HTML def bench (): import sys from time import time from itertools import izip, islice iterations = range (150) x = range (100000) def chk (name, func): t = time () for i in iterations: result = func(x) res = 'ok' if tuple (result) == (x[-2], x[-1]) else '!!' print '[%s] %10s: %0.4f' % (res, name, time ()-t) if res == '!!' : print 'auch!' print (x[-2], x[-1]) print result sys .stdout.flush() def test_zip (d): for (val1, val2) in zip (d[::2], d[1::2]): res = val1, val2 return res def test_izip (d): for (val1, val2) in izip(islice(d, 0, None, 2), islice(d, 1, None, 2)): res = val1, val2 return res def test_for (d): for ix in range (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_slice (d): for ix in range (0, len (x), 2): res = x[ix:ix+2] return res def test_ifor (d): for ix in xrange (0, len (x), 2): res = x[ix], x[ix+1] return res def test_for_enum (d): for idx, val1 in enumerate (x[::2]): res = val1, x[idx*2+1] return res def test_for_count (d): idx = -1 for val1 in x[::2]: idx += 2 res = val1, x[idx] return res def test_for_islice (d): idx = -1 for val1 in islice(x, 0, None, 2): idx += 2 res = val1, x[idx] return res chk ( 'zip' , test_zip ) chk ( 'izip' , test_izip ) chk ( 'for' , test_for ) chk ( 'for+slice' , test_for_slice ) chk ( 'ifor' , test_ifor ) chk ( 'for+enum' , test_for_enum ) chk ( 'for+cnt' , test_for_count ) chk ( 'for+islice' , test_for_islice )


結果(C2Q @ 6700)
 [780]で:ベンチ()
 [ok] zip:9.1446
 [ok] izip:1.1836
 [ok] for:1.6922
 [ok] +スライス:2.4799
 [ok] ifor:1.5846
 [ok] for + enum:1.9567
 [ok] for + cnt:1.3093
 [ok] + islice:1.3616


言い換えると、「nothing more」モードのrawカウンター(+ cntの場合)とほぼ同じくらい効果的です。 ほとんどの非反復関数(上記のzipとizipなど)の場合、反復子を返す関数もリストがはるかに小さい場合に勝ちます:

 #上記のベンチ()の値
反復=範囲(1500000)
 x =範囲(10)

 [ok] zip:3.7247
 [ok] izip:3.2949
 [ok] for:3.2703
 [ok] +スライス:3.9095
 [ok] ifor:2.9077
 [ok] for + enum:3.9383
 [ok] for + cnt:2.3443
 [ok] + islice:2.3495


しかし、ここでは、すでに通常の+カウンターが関数の呼び出しを節約します。

Source: https://habr.com/ru/post/J52474/


All Articles