Skip to main content

Simplified performance timers in Python.

Project description

Perfed

Perfed is a simplified approach to performance timing in Python.

Usage

import time
from perfed.timers import Timers

timers = Timers()

timers.start("first")
time.sleep(0.2)
timers.stop("first")

timers.start("second")
time.sleep(0.3)
timers.stop("second")

with timers.start("third"):
    time.sleep(0.4)

timers.show()

"""
Output:

Timer      Elasped Time
-------  --------------
first          0.200766
second         0.301181
third          0.400664
------CSV-----
Timer,Elasped Time
first,0.200766
second,0.301181
third,0.4006642
"""
import time
from perfed.timer_decorator import TimerDecorator

@TimerDecorator.decorate("foo_timer")
def foo(x: int):
    print(x)
    time.sleep(0.2)

@TimerDecorator.decorate("bar_timer")
def bar(x: str):
    print(x)
    time.sleep(0.3)

foo(49)
foo(200)
foo(455)

bar("cat")
bar("dog")

TimerDecorator.get_manager("foo_timer").show()
print(TimerDecorator.get_manager("foo_timer").average())
TimerDecorator.get_manager("bar_timer").show()
print(TimerDecorator.get_manager("bar_timer").average())

"""
Output:

49
200
455
cat
dog
Timer           Elasped Time
------------  --------------
foo_timer(1)        0.200183
foo_timer(2)        0.200126
foo_timer(3)        0.200508
0.20027236666666665
Timer           Elasped Time
------------  --------------
bar_timer(1)        0.300116
bar_timer(2)        0.300573
0.3003445
"""

Credit

This is heavily inspired by perfcounters. I decided to create this repository as I have some original ideas and would like to try my hand at making my own Python package.

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

perfed-0.1.0.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

perfed-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file perfed-0.1.0.tar.gz.

File metadata

  • Download URL: perfed-0.1.0.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for perfed-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5e9de400aa72dc0cf6f38d26f1282941aba9f9fe4ec787144155b808ffc50274
MD5 020d01059d2c7e4d80f286246f2e1332
BLAKE2b-256 82950b5fc6d26d462d2e9d67f941a561bd90547204386d0cc1c9456283686a9a

See more details on using hashes here.

Provenance

The following attestation bundles were made for perfed-0.1.0.tar.gz:

Publisher: publish.yaml on sohenze/perfed

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file perfed-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: perfed-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for perfed-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8a310ef0cc52ef03cb32a86cfef22eab8195cc66920965966ff77895b82ae0e
MD5 60b67c0930f5ce934233f65b073ad238
BLAKE2b-256 edad8af4ea181a7e85781858807ca402cd77bfa0659203988fab59ced324ab6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for perfed-0.1.0-py3-none-any.whl:

Publisher: publish.yaml on sohenze/perfed

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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