Skip to main content

A package that allows timing of each individual line of code in a function, and produces a colour-coded output

Project description

Deep time-it

Deep time-it is an open source module that was intended to be an extension of the timeit library, that not only times a function, but can also time each individual line and chunk of code within it, and produce a visual break-down of the slower and faster parts to aid with debugging and refactoring.

Important

Be careful if your function that you are timing has side effects. If it does, then as sometimes the function may be run twice, the side effect might occur twice. To disable double running, set the maxrepeats flag to None. This is done be default.

Installation

To install the Deep time-it library, use pip install deep_timeit. The documentation can be found at TODO. We support Python versions 3.6 to 3.10.

Usage

Run deep_timeit.deepTimeit(function), and replace function with a reference to the function you want to time. It includes the additional flags args and kwargs, which you can set to a list and dictionary respectively that includes additional arguments and keyword arguments to include when timing the function. The other flags are maxrepeats, which if set to an integer, which it is by default, will check if any lines are run more than the threshold and in which case will reattempt timing the function without timing those particular lines. This is a feature because if it times a line a large number of times, the timing itself will start to contribute to the time taken. The function returns an Info object, which can be displayed by running infoob.show().

Examples

Example 1

import deep_timeit
import time

def add(a, b):
    accumilator = 0
    for i in range(a):
      accumilator += 1
    for i in range(b):
      accumilator += 1
    print(f"The result of the addition of a and b is: {accumilator}")

deep_timeit.deepTimeit(add, args=[100000, 200000]).show()

Example 2

from deep_timeit import deepTimeit

def incrementalTime():
    """This is a function that takes incrementally long to run
    and is a good test of the range of colours."""
    for i in range(4):
        time.sleep(0.1)
        time.sleep(0.2)
        time.sleep(0.3)
        time.sleep(0.4)
        time.sleep(0.5)
        time.sleep(0.6)
        time.sleep(0.7)
        time.sleep(0.8)
        time.sleep(0.9)
        time.sleep(1)
    for i in range(2):
        time.sleep(0.1)
        time.sleep(0.2)
        time.sleep(0.3)
        time.sleep(0.4)
        time.sleep(0.5)
        time.sleep(0.6)
        time.sleep(0.7)
        time.sleep(0.8)
        time.sleep(0.9)
        time.sleep(1)
        for j in range(3):
            time.sleep(0.01)
            time.sleep(0.02)
            time.sleep(0.03)
            time.sleep(0.04)
            time.sleep(0.05)
            time.sleep(0.06)
            time.sleep(0.07)
            time.sleep(0.08)
            time.sleep(0.09)
            time.sleep(0.1)

deepTimeit(incrementalTime).show()

Example 3

from deep_timeit import deepTimeit, Colour
import random

deepTimeit(random._test).show()

Example 4

from deep_timeit import deepTimeit

def incrementalTime():
    """This is a function that takes incrementally long to run
    and is a good test of the range of colours."""
    for i in range(4):
        time.sleep(0.1)
        time.sleep(0.2)
        time.sleep(0.3)
        time.sleep(0.4)
        time.sleep(0.5)
        time.sleep(0.6)
        time.sleep(0.7)
        time.sleep(0.8)
        time.sleep(0.9)
        time.sleep(1)
    for i in range(2):
        time.sleep(0.1)
        time.sleep(0.2)
        time.sleep(0.3)
        time.sleep(0.4)
        time.sleep(0.5)
        time.sleep(0.6)
        time.sleep(0.7)
        time.sleep(0.8)
        time.sleep(0.9)
        time.sleep(1)
        for j in range(3):
            time.sleep(0.01)
            time.sleep(0.02)
            time.sleep(0.03)
            time.sleep(0.04)
            time.sleep(0.05)
            time.sleep(0.06)
            time.sleep(0.07)
            time.sleep(0.08)
            time.sleep(0.09)
            time.sleep(0.1)

deepTimeit(incrementalTime).show(colourrange=ColourRange.RAINBOW)

Release notes

Github releases

Similar libraries

  • timeit
  • line_profiler
  • pprofile

TODO's

Make code work with functions that have:

  • Multiline brackets

Make code work with:

  • Class methods
  • Recursive functions

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

deep_timeit-1.1.1.tar.gz (623.0 kB view details)

Uploaded Source

Built Distribution

deep_timeit-1.1.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file deep_timeit-1.1.1.tar.gz.

File metadata

  • Download URL: deep_timeit-1.1.1.tar.gz
  • Upload date:
  • Size: 623.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.7

File hashes

Hashes for deep_timeit-1.1.1.tar.gz
Algorithm Hash digest
SHA256 1f8b598eca58b1910af8a03380dcd84e34523a2cc2ca0e92414b850300bb5d89
MD5 2ba244aa77b5a8235dc5635941fd0df7
BLAKE2b-256 55e7bf69694a9d837ea58dbda883ad904d512eb7a9167bea7a9d465f7a534e53

See more details on using hashes here.

File details

Details for the file deep_timeit-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: deep_timeit-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.7

File hashes

Hashes for deep_timeit-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 222afaa650650787ef181b21b15ce9e21806a8e4bbefff31726fafb9522ede3d
MD5 185a1b2a2a9e9e6a0b8601c60e0f8fba
BLAKE2b-256 9fdec81e69f2c187861dd9522f386bc80eced53fc11cabdf1d944da91d6940b3

See more details on using hashes here.

Supported by

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