fork(1) download
  1. import timeit, dis
  2.  
  3. setup = "import array; a = array.array('i', [1, 2, 3])"
  4. for _ in range(2):
  5. for stmt in 'a[:]', 'a * 1':
  6. print('%-7s' % stmt, timeit.timeit(stmt, setup, number=10**7))
  7.  
  8. dis.dis(compile('a[:]', '', 'eval'))
  9. dis.dis(compile('a * 1', '', 'eval'))
Success #stdin #stdout 3.61s 9880KB
stdin
Standard input is empty
stdout
a[:]    0.9178518699482083
a * 1   0.8773866342380643
a[:]    0.9160326523706317
a * 1   0.8775129402056336
  1           0 LOAD_NAME                0 (a)
              3 LOAD_CONST               0 (None)
              6 LOAD_CONST               0 (None)
              9 BUILD_SLICE              2
             12 BINARY_SUBSCR
             13 RETURN_VALUE
  1           0 LOAD_NAME                0 (a)
              3 LOAD_CONST               0 (1)
              6 BINARY_MULTIPLY
              7 RETURN_VALUE