On Wednesday, June 29, 2016 at 6:46:04 PM UTC+12, Steven D'Aprano wrote:
> On Wednesday 29 June 2016 15:51, Lawrence D’Oliveiro wrote:
>
>> On Wednesday, June 29, 2016 at 5:26:46 PM UTC+12, Steven D'Aprano wrote:
>>> BUT in Python 3, the distinction between int and long is gone by dropping
>>> int and renaming long as "int". So all Python ints are BIGNUMs.
>>
>> I don’t understand what the problem is with this. Is there supposed to be
>> some issue with performance? Because I can’t see it.
>
> If there is a performance hit, it's probably pretty small. It may have been
> bigger back in Python 3.0 or 3.1.
>
> [steve@ando ~]$ python2.7 -m timeit -s "n = 0" "for i in xrange(10000): n +=
> i"
> 100 loops, best of 3: 1.87 msec per loop
>
> [steve@ando ~]$ python3.3 -m timeit -s "n = 0" "for i in range(10000): n += i"
> 1000 loops, best of 3: 1.89 msec per loop
Here is what I tried:
ldo@theon:python_try> python2 int_speed_test.py
2 ** 6 is 2 ** 6: True
1000000 iterations of “a = 2 ** 6 // 2 ** 4” took 0.0624719s =
6.24719e-08s/iteration
2 ** 9 is 2 ** 9: False
1000000 iterations of “a = 2 ** 9 // 2 ** 6” took 0.0506701s =
5.06701e-08s/iteration
2 ** 20 is 2 ** 20: False
1000000 iterations of “a = 2 ** 20 // 2 ** 12” took 0.0441589s =
4.41589e-08s/iteration
2 ** 64 is 2 ** 64: False
1000000 iterations of “a = 2 ** 64 // 2 ** 32” took 0.138092s =
1.38092e-07s/iteration
2 ** 96 is 2 ** 96: False
1000000 iterations of “a = 2 ** 96 // 2 ** 64” took 0.1142s =
1.142e-07s/iteration
ldo@theon:python_try> python3 int_speed_test.py
2 ** 6 is 2 ** 6: True
1000000 iterations of “a = 2 ** 6 // 2 ** 4” took 0.0230309s =
2.30309e-08s/iteration
2 ** 9 is 2 ** 9: False
1000000 iterations of “a = 2 ** 9 // 2 ** 6” took 0.0231234s =
2.31234e-08s/iteration
2 ** 20 is 2 ** 20: False
1000000 iterations of “a = 2 ** 20 // 2 ** 12” took 0.020053s =
2.0053e-08s/iteration
2 ** 64 is 2 ** 64: False
1000000 iterations of “a = 2 ** 64 // 2 ** 32” took 0.0182259s =
1.82259e-08s/iteration
2 ** 96 is 2 ** 96: False
1000000 iterations of “a = 2 ** 96 // 2 ** 64” took 0.0173797s =
1.73797e-08s/iteration
As you can see, Python 3 is actually *faster* than Python 2, particularly with
smaller-magnitude integers.
--
https://mail.python.org/mailman/listinfo/python-list