Tnx!
int* did the tric. Maybe an idea to mention this in the Cython manual.
Look at the amazing difference in speed....
sage: timeit('for x in xrange(1,100000): is_square(x,True)',number=25)
25 loops, best of 3: 1.35 s per loop
sage: timeit('for x in xrange(1,100000):
c_is_square(x,True)',number=25)
25 loops, best of 3: 37.2 ms per loop
The latter is due to a more refined exclusion method as for instance
descibed in
http://stackoverflow.com/questions/295579/fastest-way-to-determine-if-an-integers-square-root-is-an-integer
Roland
On 7 jun, 18:15, Robert Bradshaw <[email protected]> wrote:
> On Jun 7, 2010, at 8:04 AM, Rolandb wrote:
>
> > Hi,
>
> > Using cython, I want to make optimal use of static data. The reason is
> > that lookup is (often) much faster than recalulating. I now use:
>
> > cdef list nice_list_name=[3 , 3 , 3 , 3 , 3 , 3 , 4 , 4 , 4 , 4 , 4 ,
> > 4 , 4 , 4 , 4 , 5 , 5 , 5 , et cetera]
>
> > But this didn't increase the speed. Suggestions are appriciated!
>
> Perhaps in your case lookup isn't faster than recalculating? If it's
> about a tie, re-calculating is probably better, as it's less of a
> "black box." Here you're using a Python list of ints, if you really
> want speed you'd want to use a int*. You could globally calculate this
> the first time it's used and use a lookup from then on.
>
> - Robert
--
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