No project description provided
Project description
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file timemycode-1.0.3.tar.gz.
File metadata
- Download URL: timemycode-1.0.3.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.8.10 Linux/5.4.0-172-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54c4f20b22cc992b9e3aa22a1226feb93a6e4e1cfb85bea8594b8fe55c173d85
|
|
| MD5 |
ee27bcf1681caa29d32a337482707ff0
|
|
| BLAKE2b-256 |
255fad50fe641e6a8e08c68ee669c7c55f2d57897b6f41a59ad3249ca6300237
|
File details
Details for the file timemycode-1.0.3-py3-none-any.whl.
File metadata
- Download URL: timemycode-1.0.3-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.8.10 Linux/5.4.0-172-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73a203e49efcf9c1017037ae0c382919a8512e30b93eee90ae0f0d6cee4033d4
|
|
| MD5 |
ced26fbc94e3506240e3e1820ce202bd
|
|
| BLAKE2b-256 |
9e308df4e47248ce4514ffa6de15bfa8a103a08faaa9307dfd04a6882353dc12
|