473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

time.clock()

The manual says:

On Unix, return the current processor time as a
floating point number expressed in seconds.

So I ran this program:

#!/usr/bin/python

import time

while 1:
print time.clock()

This gave me a stream of floats, the integer part of which
only updated about every three seconds. Now, the manual
also states:

The precision, and in fact the very definition of the meaning
of ``processor time'', depends on that of the C function of the same name

So I "man 3 clock" and notice:

The value returned is the CPU time used so far as a clock_t; to get the number
of seconds used, divide by CLOCKS_PER_SEC.

So, I'm wondering how to get that value from python. All I
really want to do is know current time relative to a given
point so that I can capture MIDI events, and store the time
at which they arrive. Am I barking up the wrong tree?

Thanks,

Toby

--
Posted via a free Usenet account from http://www.teranews.com

Jul 14 '06 #1
5 7637
Tobiah wrote:
Am I barking up the wrong tree?
I don't think so, time.clock() has always worked fine for me. You can
also try time.time(). It is not as precise, but it might be sufficient
for your needs.
Jul 14 '06 #2
Tobiah wrote:
The manual says:

On Unix, return the current processor time as a
floating point number expressed in seconds.

So I ran this program:

#!/usr/bin/python

import time

while 1:
print time.clock()

This gave me a stream of floats, the integer part of which
only updated about every three seconds. Now, the manual
also states:

The precision, and in fact the very definition of the meaning
of ``processor time'', depends on that of the C function of the same name

So I "man 3 clock" and notice:

The value returned is the CPU time used so far as a clock_t; to get the
number
of seconds used, divide by CLOCKS_PER_SEC.

So, I'm wondering how to get that value from python. All I
really want to do is know current time relative to a given
point so that I can capture MIDI events, and store the time
at which they arrive. Am I barking up the wrong tree?
What you want sound like the 'wall clock' time. The CPU time is the time
that the CPU spent on executing your process. And unless the process uses
100% of the CPU, CPU time will appear to be 'slower' than the wall clock.
In your little program above the CPU spent about one third of the time on
this process and the rest is used for other processes (e.g. updating the
display).

What you need is time.time(), if its precision is sufficient.

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/
Jul 14 '06 #3
Tobiah wrote:
import time

while 1:
print time.clock()

This gave me a stream of floats, the integer part of which
only updated about every three seconds. Now, the manual
also states:

The precision, and in fact the very definition of the meaning
of ``processor time'', depends on that of the C function of
the same name

So I "man 3 clock" and notice:

The value returned is the CPU time used so far as a clock_t;
to get the number of seconds used, divide by CLOCKS_PER_SEC.

So, I'm wondering how to get that value from python.
by calling clock(), of course.
All I really want to do is know current time relative to a given
point so that I can capture MIDI events, and store the time at
which they arrive.
if you want real time, use time.time().

CPU time (processor time) is something different; that's based on how
many CPU cycles your program has used up since it started (usually
approximated by checking what process is running at regular intervals).
if your program doesn't do anything, or, as in your example, spends
most of its time waiting for someone else to do something, it won't
consume many cycles.

</F>

Jul 14 '06 #4
On 2006-07-14, Tobiah <to**@rcsreg.comwrote:
So I "man 3 clock" and notice:

The value returned is the CPU time used so far as a clock_t; to get the number
of seconds used, divide by CLOCKS_PER_SEC.

So, I'm wondering how to get that value from python.
What value?
All I really want to do is know current time relative to a
given point
Which is not at all the same thing as CPU usage.
so that I can capture MIDI events, and store the time at which
they arrive.
time.time()
Am I barking up the wrong tree?
Yes, but your in the right grove.

--
Grant Edwards grante Yow! "THE LITTLE PINK
at FLESH SISTERS," I saw them
visi.com at th' FLUROESCENT BULB
MAKERS CONVENTION...
Jul 14 '06 #5
Benjamin Niemann <pi**@odahoda.dewrote:
Tobiah wrote:
On Unix...
What you want sound like the 'wall clock' time. The CPU time is the time
that the CPU spent on executing your process. And unless the process uses
100% of the CPU, CPU time will appear to be 'slower' than the wall clock.
In your little program above the CPU spent about one third of the time on
this process and the rest is used for other processes (e.g. updating the
display).

What you need is time.time(), if its precision is sufficient.
In linux at least time.time() has microsecond precision.
>>for i in range(10): print "%20.6f" % time.time()
....
1153130111.566463
1153130111.566513
1153130111.566535
1153130111.566557
1153130111.566578
1153130111.566601
1153130111.566621
1153130111.566644
1153130111.566665
1153130111.566686

Wheras time.clock() only has 10 ms precision
>>for i in range(10): print "%20.6f" % time.clock()
....
1.770000
1.770000
1.770000
1.770000
1.770000
1.770000
1.770000
1.770000
1.770000
1.770000

time.clock() is elapsed cpu time of just that process.

I think the precisions are the other way round on windows.

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Jul 17 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: peterbe | last post by:
What's the difference between time.clock() and time.time() (and please don't say clock() is the CPU clock and time() is the actual time because that doesn't help me at all :) I'm trying to...
6
by: cournape | last post by:
Hi there, I have some scientific application written in python. There is a good deal of list processing, but also some "simple" computation such as basic linear algebra involved. I would like to...
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
5
by: raybakk | last post by:
Hi there. If I make a function in c (I acually use gnu right now), is there any way to find out how many clocksycluses that function takes? If I divide some numbers etc Var1 = Var2/Var3, is it...
7
by: nono909 | last post by:
I wrote the following time class for the following assignment.i need help in completing this program pleasee. Write a class to hold time. Time is the hour, minute and seconds. Write a constructor...
5
by: yinglcs | last post by:
Hi, I am following this python example trying to time how long does an operation takes, like this: My question is why the content of the file (dataFile) is just '0.0'? I have tried "print...
37
by: David T. Ashley | last post by:
I have Red Hat Enterprise Linux 4. I was just reading up about UTC and leap seconds. Is it true on my system that the Unix time may skip up or down by one second at midnight when there is a...
9
by: Ron Adam | last post by:
I'm having some cross platform issues with timing loops. It seems time.time is better for some computers/platforms and time.clock others, but it's not always clear which, so I came up with the...
8
by: Theo v. Werkhoven | last post by:
hi, In this code I read out an instrument during a user determined period, and save the relative time of the sample (since the start of the test) and the readback value in a csv file. #v+...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.