Skip to main content

A small package to help

Project description

TimeMe

A small python pacakge to time the execution of functions, organize the results, and manage larger experiments involving runtime and profiling of code.

Why TimeMe?

Ever want to test out how fast your function really is? Maybe you want to test and compare multiple functions. You used to have to write a quick block of code to time the execution of your function, and in some cases, even write your own decorator. You might then store the results in some array, compute some stats, then plot it. How many times will you do the same thing over and over again?

For example:

Say you have a function like this:

def foo():
    for i in range(10):
        print(i)

Now, if you want to time it, you have to do something like this:

import time

start = time.time()
foo()
runtime = time.time() - start

print(runtime)

Where do you store the runtime of the function? How do you make sure it is associated with the funciton foo with the particular parameters passed to it? Also what happens if you want to run multiple trials and take the average runtime?

You used to have to write all this logic yourself, but here's how it looks with TimeMe:

from timeme import Timer

@Timer(name='foo_experiment', trials=100)
def foo():
    for i in range(10):
        print(i)
        
        
foo(timeme=true)
runtime_data = Timer.records['foo_experiment']

TimeMe automatically tracks the runtime of your function as it executes, so you don't have to write any additional code. It also overrides your function parameters and adds an additional keyword argument, timeme. This allows you to toggle whether or not you want the runtime to be recorded. You can even run multiple trials. TimeMe will automatically store the data from each run and compute basic stats such as the mean and standard deviation of the trials.

The data can be retrieved in the Timer object. Want to export it as a CSV or do even more analytics?

TimeMe can export the data as a pandas dataframe so you can do as much data analysis as your heart desires.

TimeMe is a tool that will make sure you never have to write annoying boilerplate code to evaluate the runtime of your code.

Examples

Clone the repo and run the examples to see how TimeMe works for yourself.

To build the project from github, clone the repo and run the following at the root of the project directory

pip install -e .

Then navigate to the examples directory and take a look around.

Run python compare.py to get a basic assessment between bubble sort and merge sort. The code will run 100 trials on each function, record the runtime, and report the mean and standard deviations.

Run python varying_input.py to see the same functions but with varying inputs. This example will also graph the runtime of each function according to the input size. Make sure you have matplotlib installed for this example.

Questions?

Feel free to reach out at: rohin.dasari@gmail.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Please-TimeMe-0.0.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Please_TimeMe-0.0.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file Please-TimeMe-0.0.1.tar.gz.

File metadata

  • Download URL: Please-TimeMe-0.0.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for Please-TimeMe-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fce47414f2edbf02f4f15922c9f4727911ef9c8d514f108b773d1bd1eb4def19
MD5 e48fcfd90da3e69808e355398e62388c
BLAKE2b-256 417f5d9aae6daa3855303598fe708ac870d21ea6ba0f251e21eb8bda8271af04

See more details on using hashes here.

File details

Details for the file Please_TimeMe-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: Please_TimeMe-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for Please_TimeMe-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f0be9d15e2e3923d18b614908759d49ff4e3163fd789a2ec5493478e18b6311c
MD5 b783177be2b1351ab2b9520c912ab1bf
BLAKE2b-256 c6a636b97e0aaaa7e9930bff4448e1364f5798e415be29e9661e04353b73c902

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page