LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-31-2020, 09:19 AM   #1
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,845
Blog Entries: 3

Rep: Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403
High resolution time in Python3


Which module for Python3 is available to provide high resolution alarm, sleep, gettimeofday, and interval timers? I'm looking for something that can work on the level of microseconds or hopefully even nanoseconds.
 
Old 05-31-2020, 09:29 AM   #2
shruggy
Member
 
Registered: Mar 2020
Posts: 994

Rep: Reputation: Disabled
The first hit on Google gives me this answer.
 
Old 05-31-2020, 12:46 PM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 9,606

Rep: Reputation: 4279Reputation: 4279Reputation: 4279Reputation: 4279Reputation: 4279Reputation: 4279Reputation: 4279Reputation: 4279Reputation: 4279Reputation: 4279Reputation: 4279
It's just the "time" module.

https://docs.python.org/3/library/time.html
 
Old 06-02-2020, 08:43 AM   #4
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,845

Original Poster
Blog Entries: 3

Rep: Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403
Thanks. Reading more, the sleep module is supposed to do that. Using a script from a link above,

Code:
#!/usr/bin/python3

import time

# measure the smallest time delta by spinning until the time changes
def measure():
    t0 = time.time()
    t1 = t0
    while t1 == t0:
        t1 = time.time()
    return t1-t0

samples = [measure() for i in range(30)]

for s in samples:
    print(f'time delta: {s:.6f} seconds')
I can see that it is rather precise:

Code:
time delta: 0.000003 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000002 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000002 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
time delta: 0.000001 seconds
I had expected a software problem but it looks like the trouble may lie with a peripheral device which responds sluggishly.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python3 -V returns Python 2.7.12, can't get python3 to work. gene_ Ubuntu 15 03-18-2019 10:39 AM
[SOLVED] making python3.6.4 default python3 Astral Axiom Linux - Newbie 17 04-14-2018 10:55 AM
[SOLVED] how to start python3.6 interpreter just by typing python in terminal not python3.6 bmohanraj91 Linux - Newbie 4 05-10-2017 07:51 AM
After upgrade python3.4 to python3.5.1 , not able to install packages "request" though pip3 YOGESHAS87 Linux - Software 1 08-03-2016 10:38 PM
Change High Resolution Time Source taylor_ma Linux - Hardware 5 05-21-2012 08:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration