From: Grant Edwards on
What's the correct way to measure small periods of elapsed
time. I've always used time.clock() in the past:

start = time.clock()
[stuff being timed]
stop = time.clock()

delta = stop-start


However on multi-processor machines that doesn't work.
Sometimes I get negative values for delta. According to
google, this is due to a bug in Windows that causes the value
of time.clock() to be different depending on which core in a
multi-core CPU you happen to be on. [insert appropriate
MS-bashing here]

Is there another way to measure small periods of elapsed time
(say in the 1-10ms range)?

Is there a way to lock the python process to a single core so
that time.clock() works right?

--
Grant Edwards grante Yow! If I felt any more
at SOPHISTICATED I would DIE
visi.com of EMBARRASSMENT!
From: Jean-Michel Pichavant on
Grant Edwards wrote:
> What's the correct way to measure small periods of elapsed
> time. I've always used time.clock() in the past:
>
> start = time.clock()
> [stuff being timed]
> stop = time.clock()
>
> delta = stop-start
>
>
> However on multi-processor machines that doesn't work.
> Sometimes I get negative values for delta. According to
> google, this is due to a bug in Windows that causes the value
> of time.clock() to be different depending on which core in a
> multi-core CPU you happen to be on. [insert appropriate
> MS-bashing here]
>
> Is there another way to measure small periods of elapsed time
> (say in the 1-10ms range)?
>
> Is there a way to lock the python process to a single core so
> that time.clock() works right?
>
>

Did you try with the datetime module ?

import datetime
t0 = datetime.datetime.now()
t1 = t0 - datetime.datetime.now()
t1.microseconds
Out[4]: 644114

JM

From: Grant Edwards on
On 2010-02-09, Jean-Michel Pichavant <jeanmichel(a)sequans.com> wrote:
> Grant Edwards wrote:
>> What's the correct way to measure small periods of elapsed
>> time. I've always used time.clock() in the past:
>>
>> start = time.clock()
>> [stuff being timed]
>> stop = time.clock()
>>
>> delta = stop-start
>>
>> However on multi-processor machines that doesn't work.
>> Sometimes I get negative values for delta. According to
>> google, this is due to a bug in Windows that causes the value
>> of time.clock() to be different depending on which core in a
>> multi-core CPU you happen to be on. [insert appropriate
>> MS-bashing here]
>>
>> Is there another way to measure small periods of elapsed time
>> (say in the 1-10ms range)?
>>
>> Is there a way to lock the python process to a single core so
>> that time.clock() works right?
>>
>>
>
> Did you try with the datetime module ?

No. What mechanism does it use to get the current date/time?

> import datetime
> t0 = datetime.datetime.now()
> t1 = t0 - datetime.datetime.now()
> t1.microseconds
> Out[4]: 644114

That looks very broken to me. I need to measure stuff in the
1-20ms range, and the smallest value you can measure using the
method above appears to be 640ms. Thats almost 2/3 of a second.

--
Grant Edwards grante Yow! If our behavior is
at strict, we do not need fun!
visi.com
From: Grant Edwards on
On 2010-02-09, Grant Edwards <invalid(a)invalid.invalid> wrote:
> On 2010-02-09, Jean-Michel Pichavant <jeanmichel(a)sequans.com> wrote:

>> Did you try with the datetime module ?
>
> No. What mechanism does it use to get the current date/time?
>
>> import datetime
>> t0 = datetime.datetime.now()
>> t1 = t0 - datetime.datetime.now()
>> t1.microseconds
>> Out[4]: 644114
>
> That looks very broken to me. I need to measure stuff in the
> 1-20ms range, and the smallest value you can measure using the
> method above appears to be 640ms. Thats almost 2/3 of a second.

Duh. It just occurred to me that was done interactively. I'll
give the datetime module a try once I reboot my test machine
back into Windows.

--
Grant Edwards grante Yow! Is this sexual
at intercourse yet?? Is it,
visi.com huh, is it??
From: Grant Edwards on
On 2010-02-09, Jean-Michel Pichavant <jeanmichel(a)sequans.com> wrote:
> Grant Edwards wrote:
>> What's the correct way to measure small periods of elapsed
>> time. I've always used time.clock() in the past:
>>
>> start = time.clock()
>> [stuff being timed]
>> stop = time.clock()
>>
>> delta = stop-start
>>
>>
>> However on multi-processor machines that doesn't work.
>> Sometimes I get negative values for delta. According to
>> google, this is due to a bug in Windows that causes the value
>> of time.clock() to be different depending on which core in a
>> multi-core CPU you happen to be on. [insert appropriate
>> MS-bashing here]
>>
>> Is there another way to measure small periods of elapsed time
>> (say in the 1-10ms range)?
>>
>> Is there a way to lock the python process to a single core so
>> that time.clock() works right?

> Did you try with the datetime module ?
>
> import datetime
> t0 = datetime.datetime.now()
> t1 = t0 - datetime.datetime.now()
> t1.microseconds
> Out[4]: 644114

Doesn't work. datetime.datetime.now has granularity of
15-16ms.

Intervals much less that that often come back with a delta of
0. A delay of 20ms produces a delta of either 15-16ms or
31-32ms

--
Grant Edwards grante Yow! I'm receiving a coded
at message from EUBIE BLAKE!!
visi.com