Giter Club home page Giter Club logo

timer's Introduction

timer

Easy-to-use timer for tracking runtimes.

pip install sometimer

Examples

Main functionality: summary function

from sometimer import timer

# Main functionality is the summary function:
timer.new_checkpoint()
do_stuff()

timer.new_checkpoint(name='useful-name')
do_other_stuff()

...

summary = timer.summary()
print(summary)
timer summary
              -start-   -duration-
start:         0.000s     0.100s
checkpoint_0:  0.100s     2.305s
useful-name:   2.405s     0.410s
victory lap:   2.815s    12.001s
end:          14.816s

timer.__call__() returns a one-liner

timer()
>>> 'timer:	 0.202s'
# and with an active checkpoint:
timer()
>>> 'timer:	 0.303s	    checkpoint_0:  0.050s'

@time_this_method decorator to avoid clutter

Some functions are always heavy (e.g. load, data preprocessing, data augmentation) and might be useful to time:

from sometimer import time_this_method

@time_this_method
def heavy_preprocessing(data):
    pass
    
@time_this_method(name='more-descriptive-name')
def inefficient_method(data):
    pass

when run, yields:

heavy_preprocessing(data)
inefficient_method(data)

timer.summary()
>>> 'timer summary
                           -start-   -duration-
start:                      0.000s      0.000s
heavy_preprocessing:        0.000s     25.101s
more-descriptive-name:     25.101s     13.001s
end:                       38.102s'

timer's People

Contributors

viktorstagge avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.