Something surprising I just discovered:
>>> def f():
... float('1')
...
>>> def i():
... int('1')
...
>>> timeit(f, number=1000000)
0.22292590141296387
>>> timeit(i, number=1000000)
0.4127480983734131
I repeated this many times. float
always performs substantially better than int
. Why is this happening? What goes on behind the scenes?