performance question: dictionary or list, float or string?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Tue Dec 2 08:50:41 EST 2008


On Tue, 02 Dec 2008 03:41:29 -0800, bkamrani wrote:

> 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? 

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

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


> 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