[pypy-dev] Integer division

Neal Becker ndbecker2 at gmail.com
Thu Jun 1 06:52:18 EDT 2017


Tuom Larsen wrote:

> Dear list!
> 
> I noticed that integer division (`//`) is slower than floating-point
> division and integer cast. For example:
> 
>     from __future__ import division
>     from time import time
>     t = time()
>     for i in range(1, 10000):
>         for j in range(1, 10000):
>             # k = i//j # 2.12 seconds
>             k = int(i/j) # 0.98 seconds
>     print time() - t
> 
> I now integer division should be slower, but I thought that the
> `int()` would make floating division even slower.
> 
> Please, can someone explain what is going on? Is this expected behaviour?
> 
> Thank you!

I don't know about behavior in pypy, but in terms of basic CPU performance, 
my understanding is that this is expected.



More information about the pypy-dev mailing list