[ create a new paste ] login | about

Link: http://codepad.org/PChAeNB5    [ raw code | output | fork ]

Python, pasted on Apr 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import dis

def f1():
    return [x+1 for x in range(10)]

def f2():
    xs = []
    for x in range(10):
        xs.append(x+1)
    return xs

dis.dis(f1)
print '-'*80
dis.dis(f2)


Output:
  4           0 BUILD_LIST               0
              3 DUP_TOP             
              4 STORE_FAST               0 (_[1])
              7 LOAD_GLOBAL              0 (range)
             10 LOAD_CONST               1 (10)
             13 CALL_FUNCTION            1
             16 GET_ITER            
        >>   17 FOR_ITER                17 (to 37)
             20 STORE_FAST               1 (x)
             23 LOAD_FAST                0 (_[1])
             26 LOAD_FAST                1 (x)
             29 LOAD_CONST               2 (1)
             32 BINARY_ADD          
             33 LIST_APPEND         
             34 JUMP_ABSOLUTE           17
        >>   37 DELETE_FAST              0 (_[1])
             40 RETURN_VALUE        
--------------------------------------------------------------------------------
  7           0 BUILD_LIST               0
              3 STORE_FAST               0 (xs)

  8           6 SETUP_LOOP              37 (to 46)
              9 LOAD_GLOBAL              0 (range)
             12 LOAD_CONST               1 (10)
             15 CALL_FUNCTION            1
             18 GET_ITER            
        >>   19 FOR_ITER                23 (to 45)
             22 STORE_FAST               1 (x)

  9          25 LOAD_FAST                0 (xs)
             28 LOAD_ATTR                1 (append)
             31 LOAD_FAST                1 (x)
             34 LOAD_CONST               2 (1)
             37 BINARY_ADD          
             38 CALL_FUNCTION            1
             41 POP_TOP             
             42 JUMP_ABSOLUTE           19
        >>   45 POP_BLOCK           

 10     >>   46 LOAD_FAST                0 (xs)
             49 RETURN_VALUE        


Create a new paste based on this one


Comments: