why huge speed difference btwn 1.52 and 2.1?
Ron Stephens
rdsteph at earthlink.net
Sat Jun 2 22:57:14 EDT 2001
I'd like to hear an answer to this also. Have you come up with any ideas? Anyone else???
robin senior wrote:
> I have a pretty simple script for processing a flat file db, running on
> Python 2.1; I tried running it under 1.52 for kicks, and to my surprise it
> ran almost 10 times as fast! Could someone let me know why 2.1 would be so
> much slower?
>
> Cheers,
> -robin
>
> ##################
>
> import re
> import string
>
> states = {
> 'ALABAMA':'AL',
> 'ALASKA':'AK',
> 'ARIZONA':'AZ',
> 'WISCONSIN':'WI',
> 'WYOMING':'WY'}
>
> for year in range(1994, 1998):
>
> f = open('states/USA'+str(year)+'.TXT')
> counter = 1
> while(1):
> print str(year), counter
> counter = counter + 1
>
> #convert city name to allcaps (change to string.strip(f.readline())
> in 1.5.2)
> line = string.upper(f.readline().strip())
>
> #check for EOF
> if not line:
> break
>
> for state in states.keys():
> #(STATENAME) OR (STATE ABBREVIATION)
> if ( (re.search(' '+state+'( |,)', line, re.IGNORECASE)) or
> (re.search(' '+states[state]+'( |,)', line, re.IGNORECASE)) ):
> filename = string.replace(state, ' ', '_')
> g = open('states/'+filename+'/'+str(year)+'.TXT', "a")
> g.write(line)
> g.write("\n")
> g.close()
> f.close()
More information about the Python-list
mailing list