Re: Strange Execution Times
- From: Elliot Temple <curi@xxxxxxx>
- Date: Thu, 26 May 2005 23:36:30 -0700
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]
.
- Follow-Ups:
- Re: Strange Execution Times
- From: John Machin
- Re: Strange Execution Times
- Prev by Date: Re: using timeit for a function in a class
- Next by Date: Re: Access from one class to methode of other class
- Previous by thread: Re: Strange Execution Times
- Next by thread: Re: Strange Execution Times
- Index(es):
Relevant Pages
|