cStringIO rules (was Re: O(n^2) is bad - can it be fixed?)
Mark C Favas
mark at chem.uwa.edu.au
Wed May 23 06:24:58 EDT 2001
[Alex adds cStringIO to his tests, and it proves to be faster...]
>Good point! So I added it to my little measurement script:
>def AppendTest(listorarray):
> head = repr(listorarray)
> start = time.clock()
> for i in range(0, 100):
> for x in range(0, 2000):
> listorarray.append(' ')
> # print i
> stend = time.clock()
> print "%s: %.2f" % (head, stend-start)
>def AppendTest1(listorarray):
> head = repr(listorarray)
> start = time.clock()
> for i in range(0, 100):
> for x in range(0, 2000):
> listorarray.write(' ')
> # print i
> stend = time.clock()
> print "%s: %.2f" % (head, stend-start)
>AppendTest([])
>AppendTest(array.array('c'))
>AppendTest1(cStringIO.StringIO())
>and, whaddyaknow...:
>D:\py21>python oaat.py
>[]: 1.96
>array('c'): 1.57
><StringO object at 007F63B0>: 0.86
and running it on current CVS Python, on Tru64 Unix, I get:
python oaat.py
[]: 1.13
array('c'): 1.55
<StringO object at 1400e4f70>: 1.22
python oaat.py
[]: 1.13
array('c'): 1.58
<StringO object at 1400e4f70>: 1.22
So, platforms are (surprise!) different...
Mark
--
Email - mark at chem.uwa.edu.au ,-_|\ Mark C Favas
Phone - +61 9 380 3482 / \ Department of Chemistry
Fax - +61 9 380 1005 ---> *_,-._/ The University of Western Australia
v Nedlands
Loc - 31.97 S, 115.81 E Western Australia 6009
More information about the Python-list
mailing list