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.
Metadata
Release files for chronix 2.0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| chronix-2.0.0.6.tar.gz | 34.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chronix-2.0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 68.4 kB
Release files / chronix-2.0.0.6.tar.gz
| Download URL | chronix-2.0.0.6.tar.gz |
|---|---|
| Size | 34.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aaeae7dbd2fad6d7c09f936ad40d141b71aca8887298c35ef0d461f880d5afb9
|
|
BLAKE2b-256 checksum How to use checksums |
3c298a8fc378c64e5a898a2c0b0526b346e188df14ae2dfcf7d32f5ff94b67bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / chronix-2.0.0.6-py3-none-any.whl
| Download URL | chronix-2.0.0.6-py3-none-any.whl |
|---|---|
| Size | 34.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bfd473d13844d8fbb9831a9d8b6756758e4512aad9301626273363a614acb9d8
|
|
BLAKE2b-256 checksum How to use checksums |
19555b2da2215ab214b21084ee5b9c7889a05e339f60163588890e7093aaee57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|