On 24/11/2019 20:04, Marc Mezzarobba wrote:
Marc Mezzarobba wrote:
sage: def f():
....:     for i in [x]range(100000000):
....:         a+a

where a = Integer(1).

If a is made local to the function, the very expensive lookups
disappear, and we still see calls to PyLong_FromLong taking much
longer than PyInt_FromLong, as Vincent suspected.

...But these seem to come from the loop indices. And indeed:

sage: def f():
....:      a = Integer(1)
....:      for i in range(100000000):
....:          a+a

sage: %time f() # py3
CPU times: user 5.58 s, sys: 0 ns, total: 5.58 s
Wall time: 5.58 s

sage: import itertools
sage: def f():
....:      a = Integer(1)
....:      for i in itertools.repeat(1, 100000000):
....:          a+a

sage: %time f() # py3
CPU times: user 3.7 s, sys: 3.92 ms, total: 3.71 s
Wall time: 3.71 s

sage: %time f() # py2
CPU times: user 4.83 s, sys: 3.92 ms, total: 4.83 s
Wall time: 4.83 s

But then I don't understand why the empty loop ran faster under py3...
But I also no longer manage to reproduce that observation. So maybe what
one observes with that particular example is just that range() has got
slower with the int/long merge? I'd be surprised, however, if this
explained a 10% slowdown in so many things.


With xsrange(100000000) I see that py3 is a bit faster, because then the indices are indeed Sage's Integer. The reverse is true with
xsrange(100000000r).

Regards,
TB

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/b8e7c230-d144-98e8-fc68-d11d95f3cde1%40gmail.com.

Reply via email to