A performance issue when using default value

keakon keakon at gmail.com
Mon Feb 1 06:20:28 CET 2010


Even this style is 41 times faster than h2():

def i2(x=[]):
  y = x
  if not y: # add this line
    y = []  # add this line
  y.append(1)
  return y + []

print Timer('i2()','from __main__ import f2, g2, h2, i2').timeit
(TIMES)

Time: 0.00742356919664



More information about the Python-list mailing list