There are 2 functions.
def f1(n):
t = time()
m = []
for i in range(n):
m.insert(0, 0)
return time() - t
def f2(n):
t = time()
m = []
for i in range(n):
m[:0] = [0]
return time() - t
They both insert many elements to list. But the second uses slice. I know that these algorithms are bad(because O(N^2)) but looks like f2 faster than f1(I tried both Python 2 and Python 3).
(You can see time here http://rextester.com/XSPGVO38315)
Is it random or there is a reson for which f2 is better than f1? Are these function equal? If no, what is better(faster)?