Strange Execution Times

Elliot Temple curi at curi.us
Fri May 27 02:36:30 EDT 2005


On May 26, 2005, at 3:22 PM, John Machin wrote:
>
> Then post your summarised results back to the newsgroup for the  
> benefit of all -- there's this vague hope that folk actually read  
> other peoples' posts before firing off questions :-)

Here is my new version.  It runs in about .65 seconds.  The trick?   
Reading lines one at a time.  Please let me know if there's any bad  
coding practices in it!


def main():

     import md5
     import time

     f = open("data.xml", "rU")
     out = open("out.xml", "w")
     p1 = "<Password>"
     p2 = "</Password>"
     adjust = len(p1)

     t1 = time.clock()
     for line in f:
         start, end = line.find(p1) + adjust, line.find(p2)
         if end != -1:
             digest = md5.new(line[start:end]).hexdigest()
             out.write(line[:start] + digest + line[end:])
         else:
             out.write(line)

     t2 = time.clock()
     print round(t2-t1, 5)

     f.close()
     out.close()

if __name__ == '__main__': main()


-- Elliot Temple
http://www.curi.us/


---
[This E-mail scanned for viruses by Declude Virus]




More information about the Python-list mailing list