1

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?

martineau
  • 112,593
  • 23
  • 157
  • 280
ewok
  • 18,668
  • 45
  • 132
  • 245
  • Just tested `%timeit float('1')` and `%timeit int('1')` in IPython (3) and got opposite results, `int` somewhat faster than `float`... – jdehesa Mar 21 '18 at 14:37

0 Answers0