LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
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
Senior Member
 
Registered: Mar 2020
Posts: 3,670

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: 11,237

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

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

Original Poster
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
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



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 08:37 AM.

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
Open Source Consulting | Domain Registration