Skip to content

Instantly share code, notes, and snippets.

@priyadhoundiyal
Last active December 5, 2017 06:22
Show Gist options
  • Select an option

  • Save priyadhoundiyal/0a2f59bf13f917bbf41a700bd8727a43 to your computer and use it in GitHub Desktop.

Select an option

Save priyadhoundiyal/0a2f59bf13f917bbf41a700bd8727a43 to your computer and use it in GitHub Desktop.

Revisions

  1. priyadhoundiyal revised this gist Dec 5, 2017. No changes.
  2. priyadhoundiyal revised this gist Dec 5, 2017. No changes.
  3. priyadhoundiyal revised this gist Dec 5, 2017. No changes.
  4. priyadhoundiyal created this gist Dec 5, 2017.
    28 changes: 28 additions & 0 deletions timing.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    import atexit
    from time import clock

    def secondsToStr(t):
    return "%d:%02d:%02d.%03d" % \
    reduce(lambda ll,b : divmod(ll[0],b) + ll[1:],
    [(t*1000,),1000,60,60])

    line = "="*40
    def log(s, elapsed=None):
    print line
    print secondsToStr(clock()), '-', s
    if elapsed:
    print "Elapsed time:", elapsed
    print line
    print

    def endlog():
    end = clock()
    elapsed = end-start
    log("End Program", secondsToStr(elapsed))

    def now():
    return secondsToStr(clock())

    start = clock()
    atexit.register(endlog)
    log("Start Program")