Datetime with float seconds

K

kpal

Hello Everybody,

The standard datetime has 1 microsecond granularity. My application
needs finer time resolution, preferably float seconds. Is there an
alternative to the out-of-the-box datetime? Timezone support is not
essential.

Thanks,
 
G

Gabriel Genellina

The standard datetime has 1 microsecond granularity.

Note that this is the finest granularity a datetime object can store, NOT
the precision of datetime.now() by example.
My application
needs finer time resolution, preferably float seconds.

"float seconds" doesn't mean much. time.time returns float seconds, but
its precision is around 15ms on Windows.
Is there an
alternative to the out-of-the-box datetime? Timezone support is not
essential.

On Windows, use time.clock(), which internally uses
QueryPerformanceCounter. The resolution depends on your hardware, but it's
typically better than 1 microsecond. If you want to know the actual value:

py> from ctypes import *
py> kernel32=windll.kernel32
py> QueryPerformanceCounter=kernel32.QueryPerformanceCounter
py> QueryPerformanceFrequency=kernel32.QueryPerformanceFrequency
py> plonglong = POINTER(c_longlong)
py> QueryPerformanceFrequency.argtypes = [plonglong]
py> freq = c_longlong()
py> QueryPerformanceFrequency(byref(freq))
1
py> freq
c_longlong(3579545L)

That is, on my system the resolution is 1/3579545s, or better than 300ns
 
H

Hendrik van Rooyen

Hello Everybody,

The standard datetime has 1 microsecond granularity. My application
needs finer time resolution, preferably float seconds. Is there an
alternative to the out-of-the-box datetime? Timezone support is not
essential.

I am curious as to what would require less than microsecond
timing - about the only thing I can think of would be something
involving measuring the speed of light, where nanoseconds
or better would be nice.

- Hendrik
 
K

kpal

I am curious as to what would require less than microsecond
timing - about the only thing I can think of would be something
involving measuring the speed of light, where nanoseconds
or better would be nice.

You are right :) I am trying to write a scientific software that does
some satellite geodesy computations (involving the speed of light),
and I would prefer to keep all the times float, while retaining the
time and time interval arithmetics and format transformation
capabilities of datetime. The system time granularity, that is of
cause limited, is not a problem at all, as the data are to be
initialized by constructing instances from external data.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top