472,328 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 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 7541
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...
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...
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...
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...
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...
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...
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...
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...
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...
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)...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.