Skip to main content

High-precision time library for perfect timings and time management

Project description

Nanosecond v1.0

High-precision time library for perfect timings and time management.

Functions:

nanosecond
├── sleep(sec)
│   └── High-precision sleep function
├── waitDo(func, sec)
│   └── Waiting and running function in another 
│       thread, perfect for timings
├── schedule(func, sec, daemon=True)
│   ├── Schedule an action after a specified time. 
│   │   Doesn't block the thread
│   ├── cancel()
│   │   └── Cancel scheduled action
│   ├── skip()
│   │   └── Do scheduled action now
│   ├── setTime()
│   │   └── Change scheduled time
│   └── Get remaining time
└── createPoint()
    ├── getPoint()
    │   └── Returns UNIX datestamp point create date
    ├── placePoint()
    │   └── Changes point create time to current
    ├── elapsed()
    │   └── Return diff of current time and point 
    │       create time in seconds
    └── elapsedFloat()
        └── Return diff of current time and point 
            create time in float seconds

How to install:

  • First, upgrade pip:

Windows:

python -m pip install --upgrade pip

MacOS/Linux:

pip3 install --upgrade pip
  • Nanosecond package doesn't require dependencies, so you can install it without installing them:

Windows:

pip install nanosecond

MacOS/Linux:

pip3 install nanosecond
  • Congratulations! Nanosecond was installed.

How to use & Examples:

  • First, import:
import nanosecond
  • Let's try to sleep:
import nanosecond

nanosecond.sleep(1.5)
print("✅ Done!")
  • Making infinite cycle:
import nanosecond

while True:
    nanosecond.sleep(1.5)
    print("✅ It works!")
  • Now we are going to use waitDo function. It waits and starting function in new thread:
import nanosecond

nanosecond.waitDo(lambda:print("Hello world!🌍"), 2) # Waiting 2 seconds and printing
  • Schedule function is literally scheduling your function, like waitDo but without blocking main thread:
import nanosecond

nanosecond.schedule(lambda:print("It will appear in few seconds ⌚"), 1) # Schedule print in 1 second
print("I am first 😎")

Output looks like:

I am first 😎
It will appear in few seconds ⌚
Process finished with exit code 0

You can also skip or cancel this schedule using:

.schedule(...).skip() # Executes a function without waiting
  • Last function - createPoint. It creates time point for comparisons:
import nanosecond

point = nanosecond.createPoint()

def printElapsed():
    print(f"Elapsed {point.elapsed()}s ({point.elapsedFloat()}s or {point.elapsedNs()}ns)⌚")

point.placePoint() # Now point has got current time
printElapsed() # About few ms
nanosecond.sleep(1)
printElapsed() # ~1s

point.placePoint() # Reset it
printElapsed()

End

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

nanosecond-1.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

nanosecond-1.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file nanosecond-1.0.tar.gz.

File metadata

  • Download URL: nanosecond-1.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for nanosecond-1.0.tar.gz
Algorithm Hash digest
SHA256 1c60c43c8794a242f29dc6badb52762387f6004a513ebe2e76e1426f638dc252
MD5 6187e22f3f2e5190359aaff09e05105d
BLAKE2b-256 d3a19a8e667f8b16661b5d7da76c71b3b31ce859707492d93108d73ad7190905

See more details on using hashes here.

File details

Details for the file nanosecond-1.0-py3-none-any.whl.

File metadata

  • Download URL: nanosecond-1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for nanosecond-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b8aa484f536430eae7c5badd37449d70d1ccc193ca3906dbedd803d30966036
MD5 2926ba0fa884ac013c42d910bd8f1a3c
BLAKE2b-256 9c2de4d900ee7ff136b2378f79a8ee787cc59c4e24b3186601eb05de6e2adc9e

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