[pypy-dev] Dispatch on type
Armin Rigo
arigo at tunes.org
Tue Jul 15 19:28:34 CEST 2014
Hi,
On 15 July 2014 18:37, Eleytherios Stamatogiannakis <estama at 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.
A bientôt,
Armin.
More information about the pypy-dev
mailing list