I have a long list. I need to get the first element in the loop and remove it. So I'm trying to compare two functions that do it, but every time I'm getting different time execution.
from timeit import timeit
>>> def foo(l):
start = timeit()
while l:
l.pop(0)
end = timeit()
return end - start
>>> def bar(l):
start = timeit()
l.reverse()
while l:
l.pop()
end = timeit()
return end - start
l = [i for i in range(100000)]
>>> for i in range(10):
print(bar(v.copy()) - foo(v.copy()))
0.00021689999266527593
-0.015974199995980598
-0.0048112000222317874
0.0016583999822614715
-0.03471089998492971
-0.0077514999866252765
-0.0015070999943418428
0.0010934000019915402
-0.005327999999281019
0.000683299993397668
>>>
Am I doing everything right?