f



time in milliseconds by calling time.time()

I am trying to measure some system response time by using the time.time
() or time.clock() in my script.  However, the numbers I get are in
10s of milliseconds.
For example,
1248481670.34   #from time.time()
0.08                   #from time.clock()

That won't work for me, since the response time may be only a few
milliseconds.
My environment is Solaris 10 with Python 2.4.4 (#7, Feb  9 2007,
22:10:21).

SunOS 5.10 Generic_137112-07 i86pc i386 i86pc


The tricky thing is, if I run the python interpreter and import the
time module, I can get a time floating number in better precision by
calling time.time().  Do you guys have any suggestion on debugging
this problem?  Or, is there any other module I can try?  Thanks.

$ python
Python 2.4.4 (#7, Feb  9 2007, 22:10:21)
[GCC 3.4.6] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.time()
1248481930.8023829  <--I like this!
>>> time.clock()
0.0
>>>
0
7/25/2009 12:39:04 AM
comp.lang.python 77058 articles. 6 followers. Post Follow

3 Replies
1669 Views

Similar Articles

[PageSpeed] 17

In article 
<9c600f0c-f4a0-4e8c-bbb9-27f128aecc50@m7g2000prd.googlegroups.com>,
 "scriptlearner@gmail.com" <scriptlearner@gmail.com> wrote:

> I am trying to measure some system response time by using the time.time
> () or time.clock() in my script.  However, the numbers I get are in
> 10s of milliseconds.
> [...]
> The tricky thing is, if I run the python interpreter and import the
> time module, I can get a time floating number in better precision by
> calling time.time().
> [...]
> >>> time.time()
> 1248481930.8023829  <--I like this!

time.time() is returning a float in either case.  The difference you are 
seeing is purely related to how you are printing it; executing a "print" 
statement as opposed to the interactive interpreter printing a value.

Notice:

Roy-Smiths-MacBook-Pro:play$ python
Python 2.5.1 (r251:54863, Feb  6 2009, 19:02:12) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> print time.time()
1248484949.75
>>> time.time()
1248484957.151274

and further notice:

>>> x = time.time()
>>> str(x)
'1248485028.58'
>>> repr(x)
'1248485028.5814769'

Keep in mind that while a float may have a large apparent precision, 
there's no promise that the actual value returned by the OS has that much 
precision.  You should be fine if all you're looking for is ms, but I 
wouldn't count on much more than that.
0
roy (2295)
7/25/2009 1:27:10 AM
On Sat, Jul 25, 2009 at 3:27 AM, Roy Smith<roy@panix.com> wrote:

> Keep in mind that while a float may have a large apparent precision,
> there's no promise that the actual value returned by the OS has that much
> precision. =C2=A0You should be fine if all you're looking for is ms, but =
I
> wouldn't count on much more than that.

Even stronger: I wouldn't count on _anything_ more than that. On my
machine, time.time() changes value once per millisecond. I tested this
by looking at a loop that recorded time.time() 100000 times. The total
time in the loop was 61 ms; out of the 100000 numbers, 61 were higher
than the previous one, with the highest difference being 1.00017 ms,
the lowest 0.999928 ms.

--=20
Andr=C3=A9 Engels, andreengels@gmail.com
0
7/25/2009 5:47:14 AM
On Sat, 25 Jul 2009 07:47:14 +0200, Andre Engels wrote:

> On Sat, Jul 25, 2009 at 3:27 AM, Roy Smith<roy@panix.com> wrote:
> 
>> Keep in mind that while a float may have a large apparent precision,
>> there's no promise that the actual value returned by the OS has that
>> much precision.  You should be fine if all you're looking for is ms,
>> but I wouldn't count on much more than that.
> 
> Even stronger: I wouldn't count on _anything_ more than that. On my
> machine, time.time() changes value once per millisecond. I tested this
> by looking at a loop that recorded time.time() 100000 times. The total
> time in the loop was 61 ms; out of the 100000 numbers, 61 were higher
> than the previous one, with the highest difference being 1.00017 ms, the
> lowest 0.999928 ms.



I'm guessing you're running Windows, because for Windows time.time() has 
a low resolution and time.clock() is the higher resolution timer.

I'm running Linux, which is the opposite:


>>> from time import time, clock
>>> def diffs(alist):
....     deltas = []
....     for i in xrange(1, len(alist)):
....             deltas.append( alist[i] - alist[i-1] )
....     return deltas
....
>>> d = [time() for i in xrange(10000)]  # grab raw times
>>> dt = diffs(d)  # calculate the difference between each call
>>> max(dt), min(dt)
(0.00060892105102539062, 1.9073486328125e-06)
>>>
>>> d = [clock() for i in xrange(10000)]  # and again using clock()
>>> dc = diffs(d)
>>> max(dc), min(dc)
(0.010000000000000009, 0.0)

More important than the maximum and minimum time deltas is the resolution 
of ticks in each timer. Under Linux, clock() hardly ever gets updated:

>>> len(dc)  # how many time deltas?
9999
>>> len(filter(None, dc))  # how many non-zero deltas?
2

while time() gets updated frequently:

>>> len(dt)
9999
>>> len(filter(None, dt))
9999



See also the comments in the timeit module.



-- 
Steven
0
steve9679 (1985)
7/25/2009 6:18:23 AM
Reply:

Similar Artilces:

time.clock() or time.time()
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 0.0133562088013, 0.00669002532959 etc. To me it looks like time.time() gives a better measure (at least from a statistical practical point of view). peterb...

time.time or time.clock
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. if time.clock() - time.clock() < time.time() - time.time(): clock = time.clock else: clock = time.time Will this work most of the time, or is there something better? Ron On Jan 14, 7:05 am, Ron Ad...

time.time()
am I doing this wrong: print (time.time() / 60) / 60 #time.time has been running for many hours if time.time() was (21600/60) then that would equal 360/60 which would be 6, but I'm not getting 6 so I'm not doing the division right, any tips? On Sat, 24 Jan 2004 13:01:40 -0500, Bart Nessux <bart_nessux@hotmail.com> wrote: >am I doing this wrong: > >print (time.time() / 60) / 60 #time.time has been running for many hours > >if time.time() was (21600/60) then that would equal 360/60 which would >be 6, but I'm not getting 6 so I'm not doing the divisi...

Is time.time() < time.time() always true?
So, I was blazin' some mad chronix, as they say, and got on to thinking about Python. The question was, is the statement: time.time() < time.time() always true? Seems it should be false, since the statement itself occurs at one time instant.. but of course we know that python doesn't execute code that way.. So my question is, why doesn't Python work this way? (PS, I wasn't smoking anything, its a figure of speech :) ) On 21 Nov 2006 15:10:25 -0800, flamesrock <flamesrock@gmail.com> wrote: > So, I was blazin' some mad chronix, as they say, and got on to th...

RE: Is time.time() < time.time() always true?
Chris Mellon wrote: > On 21 Nov 2006 15:10:25 -0800, flamesrock <flamesrock@gmail.com> > wrote:=20 >> So, I was blazin' some mad chronix, as they say, and got on to >> thinking about Python.=20 >>=20 >> The question was, is the statement: >>=20 >> time.time() < time.time() >>=20 >> always true? Seems it should be false, since the statement itself >> occurs at one time instant.. but of course we know that python >> doesn't execute code that way.. So my question is, why doesn't >> Python work this way?=...

timing response times in milliseconds
I'm using an access xp form to present stimuli which participants in an experiment must respond to as quickly as they can. I need to time their responses as accurately as possible. At the moment I have a timer with interval set to 1 and increment a variable by 1 each timer event then compare the time of presentation with the time of the keypress. However this is very inaccurate bacuse the timer event doesn't actually happen this often, it seems to me to be quite irregular and unless I set the interval to something much slower (e.g. 500 ms) it doesn't seem to be able to keep up. It&...

delta time = time stop
I'm using Python to parse a bunch of s/w test files and make csv files for later report generation by MS ACCESS....(my boss loves the quick turn-around compared to C). Each log file may contain one or more 'sessions', and each session may contain one or more 'nodes'. Each session in the log has an ASCII start and stop time, as does each node. I have the basic parse part done for parameters, errors, etc., but noticed my routine for determining how long each session/node took (delta time) was a bit repetitive, so decided to make a 'stand-alone' routine to handle th...

Timing run time
I would like to compare the speed of two algorithms solving the same problem. As far as I understood, the tic-toc command gives the time difference between the beginning and the end of the computation, without taking into account the time spent by the processor doing something else. I'm using a multi-processor multi-users machine and the CPU time used by my process is not 100% and is not constant. The measured speeds are fluctuating so much that I can hardly conclude anything. Is it possible to obtain realistic measurements of the speed of my algorithms? Thanks for your help Dear Didi...

?TIME????????????????=/=/=/TIME?????? ?j???=/=/=/??????????
&#x2665;TIME&#x2467;&#x2461;&#x318D;&#x421;&#x41E;&#x41C;&#xC778;&#xD130;&#xB137;&#xD1A0;&#xD1A0;&#xBCA0;&#xD305;&#xC0AC;&#xC774;&#xD2B8;=/=/=/TIME&#x2467;&#x2461;&#x318D;&#x421;&#x41E;&#x41C; &#x261C;j&#x397;&#x2665;&#x261E;=/=/=/&#xC778;&#xD130;&#xB137;&#xD1A0;&#xD1A0;&#xBCA0;&#xD305;&#xC0AC;&#xC774;&#xD2B8; &#x2665;TIME&#x2467;&#x2461;&#x318D;&#x421;&#x41E;&#x41C;&#xC778;&#xD130;&#xB137;&#xD1A0;&#...

covert standard time (AMPM time) to Military time
What is the best way to covert standard time (AMPM time) to Military time? data test; input @1 mytime 5.; @6 ampm $2.; cards; 04:20AM 07:30PM 05:27AM 00:00PM 01:00AM 12:49AM 12:59PM ; run; Hi Lee, Try this... data test; input @1 mytime $ 5. @6 ampm $2.; new=compress(mytime||ampm); new_var=input(new,time8.); format new_var time.; cards; 04:20AM 07:30PM 05:27AM 00:00PM 01:00AM 12:49AM 12:59PM ; run; On Feb 12, 1:22=A0am, hummingbird10...@HOTMAIL.COM (Annie Lee) wrote: > What is the best way to covert standard time (AMPM time) to Military time= ? > > data test; > input >...

convert time in and time out
hi all, because I have a list of data that contains Clock_in and Clock_out, how can I know the total hours that have been used where I have converted it to Clock_in at 46200 and Clock_out at 48061 how can I know the total hours that have been used? by the way, did I need to create two new data to merge togather Thanks Not sure what you have or did. If those numbers represent the number of seconds since midnight, and you don't have any in and out combinations that span across midnight, you could use something like: data have; input clock_in clock_out; format x y time.; hours=3D(c...

Which To Use
Is Times the standard serif font? I'm deciding which font to use for a book I'm writing. My printer, HP 4ML PostScript, has the resident PostScript font Times Roman (strangely, the bold, italic and bold italic are Times). I recall that PageMaker 5 pushed for using Times. I now have PageMaker 7, and in its font list (the same list that appears in any application) is Times and Times New Roman. Would appreciate your explanation as to how resident printer fonts relate to whatever font I select from the font list (these are usually True Type, although there are other kinds). Also, a recomme...

Time + time.local
Hi - I cant seem to get localtime to work, can anyone share some gotchas? ## check environment is setup [dc@fox:~]$ echo $TZ Japan/Tokyo [dc@fox:~]$ irb irb(main):001:0> ENV['TZ'] => "Japan/Tokyo" # so the env is coming through ok... or is it? irb(main):021:0> u=Time.now.utc => Tue Jan 04 06:21:25 UTC 2011 irb(main):019:0> t1=Time.now.localtime => Tue Jan 04 06:21:02 +0000 2011 irb(main):020:0> t1.zone => "UTC" ### so it seems zone is being ignored # is there any way to override/forcibly set the timezone? ir...

time sync? time servers give wrong time
I'm in toronto. Eastern Standard time. I use netdate linux to sync my clock. I use: /usr/sbin/netdate -l 2 localhost 193.67.79.202 216.46.5.9 This was working fine until last week when the DST changed. Now it reports one hour behind. Every name server does this. For example: localhost +0.000 Thu Mar 13 19:17:51.519 193.67.79.202 -0.669 Thu Mar 13 19:17:51.000 216.46.5.9 -0.718 Thu Mar 13 19:17:51.000 Local host firewall has best time, so not setting date localhost +0.000 Thu Mar 13 19:17:51.718 But its 20:17 right now in EST. How do I f...

Web resources about - time in milliseconds by calling time.time() - comp.lang.python

Millisecond pulsar - Wikipedia, the free encyclopedia
A millisecond pulsar ( MSP ) is a pulsar with a rotational period in the range of about 1-10 milliseconds . Millisecond pulsars have been detected ...

Every Millisecond Counts
Site speed has always been an important factor in the development of Facebook, even as the site evolves over time to become more feature-rich ...

Stopwatch - A professional and accurate stopwatch with milliseconds precision on the App Store on iTunes ...
Get Stopwatch - A professional and accurate stopwatch with milliseconds precision on the App Store. See screenshots and ratings, and read customer ...

NVIDIA: Adam & Jamie draw a MONA LISA in 80 milliseconds! - YouTube
NVIDIA: Adam and Jamie, hosts of the known mythbusters show compared a CPU vs a GPU to explain parallel processing and the GPU drew an ACTUAL ...

DeltaDNA on real-time analytics: a lot can happen in a quarter of a millisecond - Pocket Gamer.biz ...
If there's one thing mobile developers aren&rsquo;t hurting for, it's analytics and performance tracking solutions. The real struggle in this ...

"Two hundred fifty milliseconds, either slower or faster, is close to the magic number now for..."
“Two hundred fifty milliseconds, either slower or faster, is close to the magic number now for competitive advantage on the Web” - Impatient ...

"Scientists at Harvard University found that melting glaciers have caused the length of a day to increase ...
"... a Florida police department published photos of nine unidentified, unconscious women on Facebook in an attempt to solicit information. 'We’re ...

These Ex-Googlers Got Their First Customers Milliseconds After Launching Their New Business
... been officially up and running for about a month, and business is already booming. "We got our first request to work together about 30 milliseconds ...

Milliseconds Mean Riches or Roadkill
A glitch at Thomson Reuters created a flurry of quant trading that gave retail traders no chance.

Detecting zero-day hack in one millisecond with 'power fingerprinting'
What if a vicious zero-day cyber-attack could be detected in one millisecond, discovered one thousandth of a second after the hack started? ...

Resources last updated: 2/5/2016 1:19:57 PM