On 15/7/2014 8:28 μμ, Armin Rigo wrote:
Hi,

On 15 July 2014 18:37, Eleytherios Stamatogiannakis <est...@gmail.com> wrote:
t = type(var)
if t is int:
         i(v)
elif t is long:
         l(v)
elif t is float:
         f(v)
elif t is str:
         s(v)
elif t is unicode:
         u(v)
...

This should already give you the fastest possible execution on PyPy,
because the first type inspection should promote the type in the JIT.
All subsequent "if" checks are constant-folded.  However, to be sure,
you need to check with jitviewer.

Note however that if all paths are eventually compiled by the JIT, the
promotion will have a number of different cases, and searching through
them is again done by linear search for now.  This can be regarded as
a bug waiting for improvement.

Above code gets hit millions of times with different variable types. So in our case all paths are compiled and we are linear.

Another idea that i have is the following. At startup i could sort all the hash(types), create (in a string) a python method that does binary sorting and eval it. Would the JIT be able to handle eval gymnastics like that?

Thank you.

l.

_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
https://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to