Skip to main content

Easy timing of all kinds of python code.

Project description

Timeship

The timeship lets you easily and transparently time execution times within your python code.

Its concept is that you set anchors in your code specifying timing routes. The timeship module will time the specified routes and transparently inform you about their execution time.

installation

Timeship can be installed using pip via:

pip install timeship

demo

Simply execute the following python snippet to see the timeship on sea!

import time
from timeship import timeship


with timeship.Anchor("BuildShip"):
    with timeship.Anchor("CollectMaterial"):
        time.sleep(0.2)
    with timeship.Anchor("CarftHull"):
        time.sleep(0.3)
    with timeship.Anchor("CraftMast"):
        time.sleep(0.4)
        with timeship.Anchor("HoistSail"):
            time.sleep(0.1)

with timeship.Anchor("Sail"):
    time.sleep(0.6)

timeship.plot("timeship_demo")

usage

You have two basic different options to set anchors

the anchor function

The fist option is using timeships anchor function as follows:

# set anchor Arrr
timeship.anchor("Arrr")
# execute code
time.sleep(0.1)
# release anchor Arrr
timeship.anchor("Arrr", release=True)

# set anchor Orrr
timeship.anchor("Orrr")
# execute some code
time.sleep(0.4)
# additionally set anchor Errr
timeship.anchor("Errr")
# execute some other code
time.sleep(0.4)
# release all active anchors by not specifying a name
timeship.anchor()

contexts

The second option is to use contexts

with timeship.Anchor("setup"):
    time.sleep(0.1)

nesting

The timeship also supports nested contexts. Nested timing context can be specified using a slashy (context/subcontext) notation:

timeship.anchor("xdata/load")
time.sleep(0.1)
timeship.anchor()
timeship.anchor("xdata/augment")

or by nesting contexts:

with timeship.Anchor("ydata"):
    with timeship.Anchor("load"):
        # execute ydata loading code
        time.sleep(0.2)
    with timeship.Anchor("augment"):
        # execute ydata augmentation code
        time.sleep(0.3)

or equivalently:

with timeship.Anchor("zdata/load"):
    # execute zdata loading code
    time.sleep(0.2)
with timeship.Anchor("zdata/augment"):
    # execute zdata augmentation code
    time.sleep(0.3)

plotting timing data

At the end of your code, plot the results by by using the plot function. Timeships plotting function (timeship.plot()) creates a directory (specified by the dir argument) with an index.html containing a d3 plot with the timing data which can be viewed through a webbrowser.

timeship.plot(dir="timeship")

This will create a new directory (in this case called "timeship") and store an html page, which contains a clear visualization of the timing data.

Sail on through space and time, Arrr!

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

timeship-1.0.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

timeship-1.0.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file timeship-1.0.1.tar.gz.

File metadata

  • Download URL: timeship-1.0.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

File hashes

Hashes for timeship-1.0.1.tar.gz
Algorithm Hash digest
SHA256 737c9f406c6fa6243857b670e23493430656a039ce00fc15559c3e97e54f69e8
MD5 47d5ac267fada91fc6e90b88f7963e36
BLAKE2b-256 800051f705a32bfbf5cda326cce3031790aad69e2e6256e7d005a55468d5d4f5

See more details on using hashes here.

File details

Details for the file timeship-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: timeship-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

File hashes

Hashes for timeship-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2634f48524c5d84416df35059f9644b32c6c62f1e010daf10cd3f3470e74eb96
MD5 55b4448fa49a2f9466d4066868174ad5
BLAKE2b-256 39ef3e6722feb94c2b3974aaad7f8481438b33a9666cddb35a2d2fd686610ce0

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