473,795 Members | 3,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7658
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.co mwrote:
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.d ewrote:
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.5664 63
1153130111.5665 13
1153130111.5665 35
1153130111.5665 57
1153130111.5665 78
1153130111.5666 01
1153130111.5666 21
1153130111.5666 44
1153130111.5666 65
1153130111.5666 86

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
3409
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 benchmark some function calls for Zope project and when I use t0=time.clock(); foo(); print time.clock()-t0 I get much smaller values than when I use time.clock() (most of them 0.0 but some 0.01) When I use time.time() I get values like...
6
3754
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 speed things up implementing some of the functions in C. So I need profiling. I first tried to use the default python profiler, but profiling my application multiplies the execution time by a factor between 10 and 100 ! So I decided to give a...
9
7288
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; Let's declare a constant Int32 m_TimePeriod = 10000;
17
6435
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. Note, the Windows task manager shows 2 CPUs on the Performance tab with hyper-threading is turned on. Both Python 2.3.5 and 2.4.3 (downloaded from python.org) have this problem. The operating system is MS Windows XP Professional.
5
4127
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 a fix amount of clocksycluses that is been used for that division, or does it varies? Raymond
7
7675
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 that will allow the user of your class to initialize a time or set the time to all zeros if not initialized. Include all the operators listed above. Your program will need to read from a file of times and commands. There will be a number at the top...
5
5653
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 >>dataFile, timeTaken" or "print >>dataFile,str( timeTaken)", but gives me 0.0. Please tell me what am I missing?
37
4694
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 leap second? By "Unix time" I mean the integer returned by time() and similar functions. I'm concerned about the "down" case. Some of the software I've written
9
8301
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 following to try to determine which. import time # Determine if time.time is better than time.clock # The one with better resolution should be lower.
8
1855
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+ from datetime import * from time import * from visa import *
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10435
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6779
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.