3 ms·
The difference in speed is still huge, for example sbcl (time (loop for i from 1 below (expt 10 8) by 2 when (zerop (rem i 3) count t)) this takes 0
by lli0spiyqw 4y ago
The difference in speed is still huge, for example
sbcl
(time (loop for i from 1 below (expt 10 8) by 2 when
(zerop (rem i 3) count t))
this takes 0.131 seconds
versus python
import time
def gato():
start = time.time()
s = sum(1 if i % 3 == 0 else 0 for i in range(1,10\**8,2))
end = time.time()
print(s)
print(end-start)
gato()
takes 2.26 seconds, that is 20 times the sbcl version (I am using python 3.10.6)
- camel_Snake 4y agoit's a very small thing, but the booleans in python can be added like integers, with True being 1 an False being 0. So your comprehension could have been: s = sum(i % 3 for i in range(1, 10\*8, 2))
- jstx1 4y agoDoesn't showing this in 3.10 defeat the point of the post and the gp comment?
- lli0spiyqw 4y agoYou are right, since the post say that the performance of 3.11 can be 2x that of 3.10, the implication is that python 3.11 is ten times slower on loop related code than sbcl. Anyway, a 2x improvement is a great feast for python 3.11, congratulations to the team.
- Loranubi 4y agoAnd now do it in numba or numpy, which everyone doing serious calculations would do.