Custom timer for your Python coding pleasure
Project description
code_timer
Simple python timer to use for single lines of code, or entire functions/classes
New Features!
- Use
code_timer.Timer
as a class, context manager, decorator- Offers the most versatility and flexibility for your needs
- Use separate
code_timer.timer
decorator - Use
code_timer.timeit
decorator to measure the time to run the same function multiple times- Useful when comparing the efficiency of one runtime vs another
- By default, will run the function 10,000 times. The number of runs is configurable
- DO NOT USE THIS FOR RECURSIVE FUNCTIONS!!
- Logger allowing you to set the streaming level or hide the logging entirely
Basic Usage
code_timer.Timer
-
As a class:
t = Timer(name="class") t.start() # Do something t.stop()
-
As a context manager:
-
Useful when trying to time a recursive function
with Timer(name="context manager") as t: # Do something print(f"Elapsed time: {t.elapsed_time}")
-
As a decorator:
@Timer(name="decorator") def stuff(): # Do something
code_timer.timer
-
Without braces
@timer def your_func(): # Do something
-
With braces
@timer(name="my_timer") def your_func(): # Do something
code_timer.timeit
- Time is reported at logging level: logging.INFO
- The following assumes the standard formatting for the code_timer logger
-
Default
- will repeat the function 10,000 times and report the fastest three runs
@timeit def your_func(): # Do something
- Output:
2020-03-12 21:56:46: code_timer.INFO - Best 3 of 10000 for your_func: 0.2200 ms; 0.2220 ms; 0.2232 ms
-
Pass in the number of times to repeat
@timeit(num_repeats=50) def your_func(): # Do something
- Output:
2020-03-12 21:56:46: code_timer.INFO - Best 3 of 50 for your_func: 0.2200 ms; 0.2220 ms; 0.2232 ms
- Output:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
code_timer-1.1.7.tar.gz
(5.6 kB
view details)
Built Distribution
File details
Details for the file code_timer-1.1.7.tar.gz
.
File metadata
- Download URL: code_timer-1.1.7.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ed7c94fe79b37e4eb61a7fe581a3cb9f12cb7a47950809b463076f2e139c333 |
|
MD5 | e5fe844d5b550bd9829e29fcfcf9cf7a |
|
BLAKE2b-256 | 750e5138a32b4c222054f8831930392e1e201c03697993e78d03de3436a64f90 |
File details
Details for the file code_timer-1.1.7-py3-none-any.whl
.
File metadata
- Download URL: code_timer-1.1.7-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a063ff3834f71904670cf2969002c220ab2788b70845dc7ac6fab571e34a6e95 |
|
MD5 | c8bc61e0ef660be2398fe07b3a0783e9 |
|
BLAKE2b-256 | d8f003ec7ec1465e2d68e35bd92fa214dd9c2270d14aaaf784f3defe3020b8b2 |