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 😎")
nanosecond.sleep(2) # Don't crash

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.1.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.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nanosecond-1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 f16737b2d5846dbff2968929ea8e0a94125a91db661243bd88f0f1778a6e5eb7
MD5 fecebfffc04c50a0f279f496fb4579ad
BLAKE2b-256 8baebd2a26a8d8c1a50b0f8a813ad8dd9e9b29a04848ef0583ac589053160607

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nanosecond-1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e70551eff9daee75b8a942ef86fbda2efcab258aac936a9c3c299517b01c0c96
MD5 42ddffa42af1e83d980e2ff96dd80650
BLAKE2b-256 bc94e867371f7f54564ed8372474430e0c58ee720ce510377c9288fb64e219bb

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