Skip to main content

High-precision time library for perfect timings and time management

Project description

Nanosecond

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: nanosecond-1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 530968aa65337d5555f8520bb8670e97e947b5fca37ead89f3eec01eeb2cba81
MD5 f3d8566630227b3f2f43da6999d5df60
BLAKE2b-256 d99143fdb1bb0cccf63c25b167f2e513407597f2b38ce5e8057aa2fec44e79ae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nanosecond-1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5adec3bec20df4e499897da488a3dd9a380b0713611795f9f1fcda49cbaf32bd
MD5 300327901b1f7c4d1227a61772f5fcbd
BLAKE2b-256 714486fe7383a76389a860354182b411c346bf44baf9d723416342b03f30e66f

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