performance question: dictionary or list, float or string?

bkamrani at gmail.com bkamrani at gmail.com
Thu Dec 4 04:11:17 EST 2008


Thanks for your questions. Here come some answer below.

On Dec 2, 2:50 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Tue, 02 Dec 2008 03:41:29 -0800,bkamraniwrote:
> > Hi Python gurus!
> > I'm going to read in an Ascii file containing float numbers in rows and
> > columns (say 10 columns 500000 rows) for further numerical process.
> > Which format is best to save them in, eg, dictionary, list, or numpy
> > array when it comes to performance?
>
> That depends on:
>
> (1) What do you mean by performance? Speed or memory use?

Well, I think the speed is more important in this case as the volume
of data
is not large.

> (2) Do you care about the performance of reading the data in, or the
> performance of working with the data later, or both?

The reading process is pretty fast and in range of some second, but I
meant the performance of working with data.

> (3) What do you intend to do with the numbers later?

Normal numercal calcualtion such as sum, multiplication. (but not
matrix multiplication)

Thanks
/Ben


> > Will it be beneficial to convert all strings to float directly after
> > reading or it doesn't matter to save them as string and thereafter when
> > it comes to calculation convert them to floats?
>
> That depends on what you intend to do with them. Since you're doing
> numerical processing, it's probably a good idea to convert them to
> numbers rather than strings.
>
> --
> Steven




More information about the Python-list mailing list