Skip to main content

Every concept timer you've ever seen, rolled into one. It has all the helpful features you could ever want.

Project description

Active Development CI Test Status License: LGPL-2.1 PyPI Downloads coverage

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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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

chronix-2.0.0.6.tar.gz (34.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chronix-2.0.0.6-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file chronix-2.0.0.6.tar.gz.

File metadata

  • Download URL: chronix-2.0.0.6.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

Hashes for chronix-2.0.0.6.tar.gz
Algorithm Hash digest
SHA256 aaeae7dbd2fad6d7c09f936ad40d141b71aca8887298c35ef0d461f880d5afb9
MD5 84010540c4123e8dfd336bf30bcf8801
BLAKE2b-256 3c298a8fc378c64e5a898a2c0b0526b346e188df14ae2dfcf7d32f5ff94b67bf

See more details on using hashes here.

File details

Details for the file chronix-2.0.0.6-py3-none-any.whl.

File metadata

  • Download URL: chronix-2.0.0.6-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

Hashes for chronix-2.0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 bfd473d13844d8fbb9831a9d8b6756758e4512aad9301626273363a614acb9d8
MD5 f739774c6319a381c4cc47a0bbc4d14d
BLAKE2b-256 19555b2da2215ab214b21084ee5b9c7889a05e339f60163588890e7093aaee57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page