[Tutor] Dictionaries or Numpy?
Adam Clarridge
adam.clarridge at gmail.com
Sat May 17 18:12:10 CEST 2008
On 5/16/08, John Fouhy <john at fouhy.net> wrote:
>
> On 17/05/2008, Adam Clarridge <adam.clarridge at gmail.com> wrote:
> > I'm fairly new to Python, and I am not sure whether it would be faster
> > for me to use a Dictionary data type to represent the board
> > (advantages: indices can be strings or tuples, and the dictionary can
> > store different types of data as well, so programming would be easier)
> > or the Numpy array type (don't know much about this, but I have heard
> > Numpy is faster).
>
>
> Hi Adam,
>
> I believe a general rule of programming is: don't optimize until you
> know you need to. I would advise using dictionaries for simplicity.
> If the program turns out slower than you would like, you can use
> profiling tools to figure out where in the code it is spending most of
> its time. If this turns out to involve dictionary lookups, you could
> then look at changing to Numpy (hint: you could use the timeit module
> to benchmark dictionary access against Numpy arrays). If your program
> design is good, the change should be too hard.
>
>
> http://en.wikipedia.org/wiki/Optimization_(computer_science)#When_to_optimize
>
> --
>
> John.
Thanks for the insight - I guess I was sort of overlooking that general
principle, good to be reminded. The timeit module seems like exactly what I
would want later on, too. Thanks again!
Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080517/00b09d71/attachment.htm>
More information about the Tutor
mailing list