Dear sage-support,
at #10496, David Roe gave me the advice to use PY_TYPE_CHECK rather
than isinstance in Cython files. I did so.
But actually I didn't know PY_TYPE_CHECK at all, and so I have a two
questions:
1) Apparently there are several PY_... functions. Where can I read
about them?
2) Is PY_TYPE_CHECK really quicker than isinstance?
It doesn't seem so, actually.
In testtype.pyx, I wrote
cpdef t1(x):
return PY_TYPE_CHECK(x,int)
cpdef t2(x):
return isinstance(x,int)
Then, I got the following timings:
{{{
sage: attach typecheck.pyx
Compiling typecheck.pyx...
sage: t1(5)
False
sage: t1(int(5))
True
sage: t2(5)
False
sage: t2(int(5))
True
sage: timeit("a=t1(5)")
625 loops, best of 3: 218 ns per loop
sage: timeit("a=t2(5)")
625 loops, best of 3: 205 ns per loop
sage: timeit("a=t1(int(5))")
625 loops, best of 3: 416 ns per loop
sage: timeit("a=t2(int(5))")
625 loops, best of 3: 401 ns per loop
}}}
So, actually isinstance is slightly quicker than PY_TYPE_CHECK. Or do
I misunderstand something?
Best regards,
Simon
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org