A small timer utility that has all the helpful features you could ever want!
Project description
chronix
chronix is every concept timer you've ever seen, rolled into one. It has all the helpful features you could ever want.
Compatibility
🟩 (Works perfectly); 🟨 (Untested); 🟧 (Some Issues); 🟥 (Unusable)
| OS | |
|---|---|
| Windows | 🟩 |
| MacOS | 🟩 |
| Linux (Ubuntu 22.04 LTS) | 🟩 |
Features
- Easy to use for beginners, but not lacking for experts
- Efficient
- Fully cross-platform
- Regular updates and support
- Comprehensive documentation
Installation
You can install chronix via pip:
pip install chronix --pre --upgrade
Or clone the repository and install manually:
git clone https://github.com/Adalfarus/chronix.git
cd chronix
python -m pip install .
If you have problems with the package please use py -m pip install chronix[cli,dev] --pre --upgrade --user
📦 Usage
The examples below use the public API exactly as implemented in this repository.
Basic elapsed time (BasicTimer)
import time
from chronix import BasicTimer
timer = BasicTimer(auto_start=True)
time.sleep(0.2)
timer.stop()
print(timer.get()) # datetime.timedelta(...)
print(timer.get_readable()) # "0.2 seconds, ..."
Split/lap-like checkpoints with averages (BasicTimer)
import time
from chronix import BasicTimer
timer = BasicTimer().start()
time.sleep(0.05)
timer.split_start() # start -> now
time.sleep(0.08)
timer.split_end() # last stop/start -> now
print(timer.get_times()) # [(start, split1), (split1, split2)]
print(timer.tally()) # total seconds as float
print(timer.average()) # average segment as timedelta
Precise delta parsing and formatting (PreciseTimeDelta)
from chronix import PreciseTimeDelta, PreciseTimeFormat
delta = PreciseTimeDelta.parse_timedelta_string("01:02:03.4")
print(delta.nanoseconds()) # 3723400000000.0
print(delta.to_readable(PreciseTimeFormat.SECONDS))
print(delta.to_clock_string()) # clock-style representation
Flexible timer with explicit start/stop (FlexTimer)
from chronix import FlexTimer
t = FlexTimer(start_now=False)
t.start(start_at=1.25) # pre-load elapsed time
t.wait(0.2)
t.lap() # record a lap
t.stop()
print(t.get().to_readable())
print(t.show_laps())
Track multiple timers by index (FlexTimer)
from chronix import FlexTimer
t = FlexTimer(start_now=False)
t.start(0, 1) # start two independent timers
t.wait_ms(20)
t.stop(0)
t.wait_ms(10)
t.stop(1)
print(t.get(0).to_readable()) # shorter
print(t.get(1).to_readable()) # longer
Decorator timing for functions
from chronix import FlexTimer
@FlexTimer.time()
def build_values(n: int) -> list[int]:
return [i * i for i in range(n)]
build_values(100_000)
Context manager timing for code blocks
from chronix import CPUFTimer
with CPUFTimer():
sum(i * i for i in range(200_000))
CPUFTimer uses process CPU time, so sleep/wait time is mostly excluded.
Schedule delayed and repeated callbacks
from chronix import FlexTimer
timer = FlexTimer(start_now=False)
timer.after(1.0, print, args=("one-shot fired",))
timer.interval(0.5, 3, print, args=("interval fired",))
timer.schedule_task_at("23:59", print, args=("scheduled for clock time",))
Long-running loop you can stop manually
from chronix import FlexTimer
timer = FlexTimer(start_now=False)
timer.interval(0.25, "inf", print, args=("tick",))
# ... later
timer.stop_loops(0)
Estimate time complexity of a function
from chronix import FlexTimer
def work(n: int) -> int:
return sum(range(n))
def inputs():
for n in range(1_000, 20_000, 1_000):
yield ((n,), {})
print(FlexTimer.complexity(work, inputs())) # e.g. "O(N)"
FlexTimer.complexity requires optional dependencies: numpy, scipy, and scikit-learn.
CLI examples
Install CLI extras if needed:
pip install "chronix[cli]"
Show help:
chronix help
Run all tests from the CLI:
chronix tests run
Run selected tests in minimal mode:
chronix tests run tests -minimal
For more detailed usage and examples, check out our documentation.
Naming convention, dependencies and library information
PEP 8 -- Style Guide for Python Code
For modules I use 'lowercase', classes are 'CapitalizedWords' and functions and methods are 'lower_case_with_underscores'.
Contributing
We welcome contributions! Please see our contributing guidelines for more details on how you can contribute to chronix.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a pull request
Aps Build master
You can use the aps_build_master script for your os to make your like a lot easier. It supports running tests, installing, building and much more as well as chaining together as many commands as you like.
This example runs test, build the project and then installs it
call .\aps_build_master.bat 234
sudo apt install python3-pip
sudo apt install python3-venv
chmod +x ./aps_build_master.sh
./aps_build_master.sh 234
License
chronix is licensed under the LGPL-3.0 License - see the LICENSE file for 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
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 chronix-2.0.0.5.tar.gz.
File metadata
- Download URL: chronix-2.0.0.5.tar.gz
- Upload date:
- Size: 34.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67052ddf8098d95413bd47958d218dbfd16fc9df8401d99942d03243f7979241
|
|
| MD5 |
45b258c96ee3e3ed01a11d110f6730f5
|
|
| BLAKE2b-256 |
10b9e59baebf937b52cdf6c65f3506be4454627724c4539021f24723795b94b3
|
File details
Details for the file chronix-2.0.0.5-py3-none-any.whl.
File metadata
- Download URL: chronix-2.0.0.5-py3-none-any.whl
- Upload date:
- Size: 34.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2acb8248bf0b5cc73e6f362c2727c52b26f693f8e743a254a409d487fe135dc3
|
|
| MD5 |
dc6cb8ae5822582e1eb0a2b5e2d9f7f6
|
|
| BLAKE2b-256 |
b1f938776e9ffe69a696a56763113d1ef31f747671031ca56ea0b8cb9546ff3e
|