Code Monkey home page Code Monkey logo

alexlambson / stopwatch Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 2.82 MB

A stopwatch with laps to help do traces of your code and log the whole timer in a single logging call. If you're asking "why not use real traces?" then you don't need this. This is for projects that can't use real traces for timing for whatever reason, but who have logging.

Home Page: https://alexlambson.github.io/stopwatch/

License: Mozilla Public License 2.0

Makefile 3.88% Python 96.12%
python3 timing

stopwatch's Introduction

Python Stopwatch

A helper to time your code in a granular way without a ton of bloat.

Useful for people who don't have a metrics service, but do have some form of logging.

Github project: https://github.com/alexlambson/stopwatch/

The main class that a user will be interested in is {py:class}src.stop_watch.StopWatch

Usage

Consider the manual way of timing:

import time

def do_second_thing(timer: float):
    stuff()
    print(f"Stuff took: {time.time() - timer}")
    more_stuff()
    return

start = time.time()
do_something()
do_another_thing()
print(f"Doing two things took: {time.time() - start} seconds")

start2 = time.time()
do_second_thing(start2)
print(f"Doing second thing set took: {time.time() - start2}")
print(f"Total time: {time.time() - start}")

Now with stop watch

import stopwatch

def do_second_thing(timer: StopWatch):
    stuff()
    timer.lap("do_second_thing.stuff_took")
    more_stuff()
    return

timer = stopwatch.StopWatch()
do_something()
do_another_thing()
timer.lap("Doing two things")

do_second_thing()
timer.lap("second_thing")
# timer.stop() can be called manually, but will also be called inside __str__
print(timer)

stopwatch's People

Contributors

alexlambson avatar

Watchers

 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.