why huge speed difference btwn 1.52 and 2.1?

Nick Perkins nperkins7 at home.com
Sun Jun 3 01:58:32 EDT 2001


..have you profiled the script under each version?
(i have no other ideas, sorry)



"Ron Stephens" <rdsteph at earthlink.net> wrote in message
news:3B18587D.11851C1B at earthlink.net...
> 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