Skip to main content

package: TimeMyCode

The goal of this package is to time the execution of differents parts of a Python code.

1. Initiate the global timer

The package TimeMyCode depends of the built-in packages contextlib and time.

The design of the class TimeMyCode is based on the Singleton pattern. So all new instance inside the code refer finally to the same object.

Just need to import the package:

> from timemycode import TimeMyCode as TMC

To use it, just call the class to get the object:

> with TMC().tag("test 1"):
>    ...

2. Use the global timer in your code

As this package uses a context manager, we have to use it with the statement "with". To time a new part of code, we have to use a new tag.

> with TMC().tag("This is my new tag"):
>     ...

The same tag could be use in different parts inside your code.

3. Print the time log

At the end of the process you want to time, you could display the global time log by calling the method summary().

Note: the method summary() reinitiate the timer.

> print(TMC().summary())

Time log:
  - This is my new tag ....... 6.01s ->  1 it [6.0100 s/it]

Total time: 6.02s

Details:

  • the tag name
  • the total execution time for this tag
  • the number of iterations (number of calls of this tag)
  • the time per iteration

4. Example with a For loop

> for i in range(5):
>     with TMC().tag('for 1'):
>         sleep(0.5)
> 
>         for i in range(15):
>             with TMC().tag('  for 2'):
>                 sleep(0.1)
> 
> print(TMC().summary())

Time log:
  - for 1 ..... 10.02s ->  5 it [2.0034 s/it]
  -   for 2 ...  7.51s -> 75 it [0.1002 s/it]

Total time: 10.02s

Release files for timemycode 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for timemycode 1.0.3
File Size Uploaded
timemycode-1.0.3.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for timemycode 1.0.3
File Interpreter ABI Platform
timemycode-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / timemycode-1.0.3.tar.gz

Download URL timemycode-1.0.3.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
54c4f20b22cc992b9e3aa22a1226feb93a6e4e1cfb85bea8594b8fe55c173d85
BLAKE2b-256 checksum
How to use checksums
255fad50fe641e6a8e08c68ee669c7c55f2d57897b6f41a59ad3249ca6300237
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.10 Linux/5.4.0-172-generic

Release files / timemycode-1.0.3-py3-none-any.whl

Download URL timemycode-1.0.3-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
73a203e49efcf9c1017037ae0c382919a8512e30b93eee90ae0f0d6cee4033d4
BLAKE2b-256 checksum
How to use checksums
9e308df4e47248ce4514ffa6de15bfa8a103a08faaa9307dfd04a6882353dc12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.10 Linux/5.4.0-172-generic

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page