Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hmmm, using <a href="http://docs.python.org/library/dis.html">dis</a> to show the python bytes codes shows that the functions are identical. Python has optimised the constant (as expected). So I suspect the time differences are caching effects. The timings on my laptop bear this out (using Python 2.7.3 64 bit on linux)</p> <pre><code>Fri May 11 23:37:49 2012 results 8 function calls in 38.825 seconds Ordered by: call count, name/file/line ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 1 0.000 0.000 38.825 38.825 &lt;string&gt;:1(&lt;module&gt;) 1 0.000 0.000 38.825 38.825 z.py:31(run_tests) 1 7.880 7.880 7.880 7.880 z.py:6(test1) 1 7.658 7.658 7.658 7.658 z.py:11(test2) 1 7.806 7.806 7.806 7.806 z.py:16(test3) 1 7.784 7.784 7.784 7.784 z.py:21(test4) 1 7.697 7.697 7.697 7.697 z.py:26(test5) </code></pre> <p>All pretty much identical</p> <pre><code>&gt;&gt;&gt; from dis import dis &gt;&gt;&gt; def test1(): ... for i in xrange(AMOUNT): ... value = i % 65536 ... return ... &gt;&gt;&gt; def test5(): ... for i in xrange(AMOUNT): ... value = i % (2**16) ... return ... &gt;&gt;&gt; dis(test1) 2 0 SETUP_LOOP 30 (to 33) 3 LOAD_GLOBAL 0 (xrange) 6 LOAD_GLOBAL 1 (AMOUNT) 9 CALL_FUNCTION 1 12 GET_ITER &gt;&gt; 13 FOR_ITER 16 (to 32) 16 STORE_FAST 0 (i) 3 19 LOAD_FAST 0 (i) 22 LOAD_CONST 1 (65536) 25 BINARY_MODULO 26 STORE_FAST 1 (value) 29 JUMP_ABSOLUTE 13 &gt;&gt; 32 POP_BLOCK 4 &gt;&gt; 33 LOAD_CONST 0 (None) 36 RETURN_VALUE &gt;&gt;&gt; dis(test5) 2 0 SETUP_LOOP 30 (to 33) 3 LOAD_GLOBAL 0 (xrange) 6 LOAD_GLOBAL 1 (AMOUNT) 9 CALL_FUNCTION 1 12 GET_ITER &gt;&gt; 13 FOR_ITER 16 (to 32) 16 STORE_FAST 0 (i) 3 19 LOAD_FAST 0 (i) 22 LOAD_CONST 3 (65536) 25 BINARY_MODULO 26 STORE_FAST 1 (value) 29 JUMP_ABSOLUTE 13 &gt;&gt; 32 POP_BLOCK 4 &gt;&gt; 33 LOAD_CONST 0 (None) 36 RETURN_VALUE &gt;&gt;&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload