Re: Strange Execution Times




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]

.



Relevant Pages

  • Re: Strange Execution Times
    ... benefit of all -- there's this vague hope that folk actually read other peoples' posts before firing off questions :-) ...
    (comp.lang.python)
  • Re: Strange Execution Times
    ... of all -- there's this vague hope that folk actually read other peoples' posts before firing off questions :-) ...
    (comp.lang.python)
  • Re: The internet: has it become a wasteland?
    ... been reading books (mostly history but some economics and ... newsgroups posts and reading newsgroup posts, ... I dont think I miss much. ... There is a limitless amount of idiots in the world...and only ...
    (sci.research.careers)
  • Re: Porsche 911 (996) Tiptronic - good? Paging TDM!
    ... I meant what I said about enjoying reading your posts by the way. ... After first reading the thread about your friend buying the Porsche, ... I still don't get the rampant sex joke? ...
    (uk.rec.cars.modifications)
  • Re: OT: PING Don Bowey
    ... I've been reading your posts - informative and clear, ... Beyond that, a President with any courage, intelligence and leadership ... is that no one Party is responsible for the mess ...
    (sci.electronics.design)