Skip to main content

Awesome clock_timer created by maycuatroi

Project description

Clock Timmer

Clock Timmer is a Python library that provides a tool for logging the time and number of calls of a function in Python. It can be used as a decorator or context manager, allowing you to log the time and number of calls of a function or block of code without modifying any lines of code within the function or block.

Installation To install Clock Timmer, use the following command:

pip install python-clock-timer

Usage

As a decorator

To use Clock Timmer as a decorator, you can use it like this:

from clock_timer import ClockLogger

logger = ClockLogger()

@logger
def my_function():
    # code of the function

After using the decorator, you can access the time and number of calls logs of the function by accessing the log attribute of the Clock Timmer object. For example, to get the number of calls and total time elapsed of the my_function, you can do the following:

print(logger.log['my_function'])

As a context manager

To use Clock Timmer as a context manager, you can use it like this:

from clock_timer import ClockLogger

with ClockLogger() as logger:
    # code of the block

print(logger.elapsed)

After using the context manager, you can access the total time elapsed by accessing the elapsed attribute of the Clock Timmer object.

Example

Here is an example of using Clock Timmer as a decorator and a context manager:

from clock_timer import ClockLogger
import time

# Using Clock Timmer as a decorator
logger = ClockLogger()

@logger
def my_function():
    time.sleep(1)

my_function()
my_function()

print(logger.log['my_function'])

the output

my_function was called 1 times, total time elapsed: 1.005031s
my_function was called 2 times, total time elapsed: 2.005123s
[2, 2.0051226250000003]

Using Clock Timmer as a context manager

import time

from clock_timer import ClockLogger

with ClockLogger() as logger:
    time.sleep(1)

print(logger.elapsed)

The output of this example will be:

Total time elapsed: 1.003622s
1.003622042

Contributing

We welcome contributions to Clock Timmer. If you have any ideas for improvements or want to report a bug, please open an issue or submit a pull request.

License

Clock Timmer is licensed under the MIT License. See the LICENSE file for more details.

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

python-clock-timer-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

python_clock_timer-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file python-clock-timer-0.1.0.tar.gz.

File metadata

  • Download URL: python-clock-timer-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for python-clock-timer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d0bd7377b7eed58bea343fcdd9777fb27fa93bd46af6b28c1a9606837dcf5f9e
MD5 d11e07af9f646e1e82ad7f9c0b841306
BLAKE2b-256 7a8761f1a49b87f700c953b7e350baf200cb1ec3b40d6c2273748658fc42321d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_clock_timer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c4659c7b3a10fd2ac0238aaa2234ae3d0857d2861792f8e0de5065fc0b94d4a
MD5 07e8cee6d6140e38232ce6074c8ef785
BLAKE2b-256 b985822c3a80bf02b36f639b7f89c1af11bea6c67c010cc30741f2d7902e0b47

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