On Nov 8, 2008, at 7:56 PM, tav wrote:

> Hey all,
>
> Apologies if this is the wrong list to post to -- I couldn't find a
> cython-users list...

This is the right list.

> I've been using Cython to speed up instantiation of a Namespace object
> written in Python: http://paste.lisp.org/display/69989
>
> Fundamentally, what I am trying to do is:
>
> class Namespace:
>   def __init__(self, **env):
>     global id, store
>     id += 1
>     keys = store[id] = sorted(env)
>     new_env = []
>     for key in keys:
>         obj = env[key]
>         if PyFunction_Check(obj):
>             obj = staticmethod(obj)
>         new_env.append(obj)
>     self.env = new_env
>
> The sort() and looping (for key in keys) seems to take up most of the
> time... how can I do this better so that it takes less time?

Short of writing your own sort algorithm there's not much of a way to  
speed up sort(). If you're just sorting strings here, that could  
probably be done a lot faster. However, depending on the size of env  
I might ask how important it is to have them sorted.

As mentioned earlier, declaring new_env and keys as a list could help  
the .append method go faster. The "for key in keys" should be  
relatively fast, much faster than it is in Python.

> The Cython version so far is at http://paste.lisp.org/display/69988
>
> Please forgive my Cython newbie errors... Thanks!
>
> -- 
> love, tav
>
> plex:espians/tav | [EMAIL PROTECTED] | +44 (0) 7809 569 369
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to