Time epsilon....

eigen

Diamond Member
Nov 19, 2003
4,000
1
0
I am quite familiar with the idea of Machine Epsilon from my working with Linear Algebra libraries etc and understand why such situations arise...In some of my more recent working I have started to measure the time of execution (of course relative to my architecture). I wonder is the smallest unit of time measurable is a hardware limitation ( I assume it is) but if not how can I f up my machine to make it more precise. i.e are there modules I can use to do this.....
If possible provide a good link for a non-EE ( I am math so a few equations are OK) on how computers measure time....





This all of course leads to questions about the discreteness or continuity of the physical universe given the limits of computation but thats another thread.
 

f95toli

Golden Member
Nov 21, 2002
1,547
0
0
There is definitly a hardware limitation, the maximim resolution is simply the inverse of the clock frequency; with a 1 GHz clock you get 1/1^9= 1ns resolution.

It reality it is a bit more complicated than that because resolution does not tell you much about the real accuracy, the clock is not perfect and the error accumulates; this means that if you try to measure a time intervall of 1s with a 1 GHz clock you might need more (or less) than 1e9 clock cycles.

I am not sure about the accuracy of modern CPUs but generally speaking computers are not very good at measuring time.

 

eigen

Diamond Member
Nov 19, 2003
4,000
1
0
Originally posted by: f95toli
There is definitly a hardware limitation, the maximim resolution is simply the inverse of the clock frequency; with a 1 GHz clock you get 1/1^9= 1ns resolution.

It reality it is a bit more complicated than that because resolution does not tell you much about the real accuracy, the clock is not perfect and the error accumulates; this means that if you try to measure a time intervall of 1s with a 1 GHz clock you might need more (or less) than 1e9 clock cycles.

I am not sure about the accuracy of modern CPUs but generally speaking computers are not very good at measuring time.

Thnx. I had this question as I have been compiling and testing code in mathematica and have had the time of execution to be the same for some of the smaller examples I have been working with.
The mathematica function $TimeUnit gives the smallest unit of measurable time of my system this return 10^-3
 

f95toli

Golden Member
Nov 21, 2002
1,547
0
0
10^-3=1ms is NOT a hardware limit, your computer should be able to better than that.

The main problem ís often the OS, the program that tries to measure time does not have exclusive access to the CPU, meaning that it can not simply count clock-cycles in order to know how much time has passed.

This can be avoided by a using Real-Time OS (RTOS), in RTOS you KNOW how many clock-cycles an instruction will take and I guess you can use that to measure time (with ns resolution).

You can also buy a counter-card such as the PCI-6601 fron National Instruments, it has an on-board clock with 50ns resolution which you can start/stop either from within a program or from an external signal, there are also RF-counters available with sub ns resolution but they are quite expensive.
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
Originally posted by: f95toli
10^-3=1ms is NOT a hardware limit, your computer should be able to better than that.

The main problem ís often the OS, the program that tries to measure time does not have exclusive access to the CPU, meaning that it can not simply count clock-cycles in order to know how much time has passed.

This can be avoided by a using Real-Time OS (RTOS), in RTOS you KNOW how many clock-cycles an instruction will take and I guess you can use that to measure time (with ns resolution).

You can also buy a counter-card such as the PCI-6601 fron National Instruments, it has an on-board clock with 50ns resolution which you can start/stop either from within a program or from an external signal, there are also RF-counters available with sub ns resolution but they are quite expensive.
:thumbsup:

If you're working in Windows, 1 ms is about as small as you can measure (there are exceptions, but that's a good rule of thumb). I'm trying to do something similar for a project I'm working on and we had to resort to buying a separate hardware module that measures time independently.
 

FrankSchwab

Senior member
Nov 8, 2002
218
0
0
I've always thought that some generation of processors should include an internal 64 (or 128) bit register that simply counts clock cycles. Trivial bit of hardware to implement, but would give an exceptionally quick answer whose accuracy linearly scales with processor speed to the question "How long did this take". Make one call at the beginning of your program to determine processor clock speed, and with a quick scaling you can have accurate time to whatever arbitrary measure you want (limited by CPU speed).

les di, [TimeCounter]

Simple, eh?

/frank
 

Matthias99

Diamond Member
Oct 7, 2003
8,808
0
0
Originally posted by: FrankSchwab
I've always thought that some generation of processors should include an internal 64 (or 128) bit register that simply counts clock cycles. Trivial bit of hardware to implement, but would give an exceptionally quick answer whose accuracy linearly scales with processor speed to the question "How long did this take". Make one call at the beginning of your program to determine processor clock speed, and with a quick scaling you can have accurate time to whatever arbitrary measure you want (limited by CPU speed).

les di, [TimeCounter]

Simple, eh?

/frank

Most modern processors have this (usually either 32- or 64-bit, down to microseconds or nanoseconds depending on the architecture). It's usually accessed through a call like get_hr_timer() (I forget what the Windows API to this is... would have to check in VC++). Measuring the time a particular function takes to execute in the foreground is easy.

The issue arises when you want to do things asynchronously... especially if you want to wait for defined (but very precise) time intervals without monopolizing the processor. In Windows, the thread scheduler is time-sliced to 10ms intervals. So if you have a sleep() function that takes a value in ms to sleep for, sleep(1), sleep(5), and sleep(10) are all probably going to sleep for ~10ms on a Windows machine, maybe longer (or maybe less, if another thread yield()s back to the scheduler in <10ms). It's just not predictable, and it's not fast enough for really precise work. Hence the need for an RTOS.
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
Does anyone have an example of an RTOS? I'm trying to do something in very small time increments and would love to be able to do it with minimal hardware. I've only ever used Windows (and DOS). I'll be hauling a laptop around with my measurement device so I can use the ultrasound equipment from another department, so doing away with extra hardware would be extremely helpful.
 

ghackmann

Member
Sep 11, 2002
39
0
0
QNX and BeOS are both RTOSes. Both were free downloads for non-commercial use at some point in time, but I don't know if that's still true (especially since Be went under a while back).
 

cquark

Golden Member
Apr 4, 2004
1,741
0
0
Originally posted by: eigen
Thnx. I had this question as I have been compiling and testing code in mathematica and have had the time of execution to be the same for some of the smaller examples I have been working with.
The mathematica function $TimeUnit gives the smallest unit of measurable time of my system this return 10^-3

UNIX has microsecond timers, though actual resolution tends to be limited to 10s of microseconds. For better resolution, you need a real time OS like QNX or RTLinux.
 

onix

Member
Nov 20, 2004
66
0
0
It's interesting that accessing the quartz crystal oscillator which must be part of all computers requires a special OS. Certainly the BIOS must have access to it, otherwise it wouldn't be able to maintain time while the computer is off.

For those of you using the computer to time external (electrical) signals you can always buy an cheap USB compatible oscilloscope. I've been very happy with USB Instruments Stingray product.
 

FrankSchwab

Senior member
Nov 8, 2002
218
0
0
Actually, the timekeeping crystal inside most PC's is only 32,768 Hz, which would still be nice in giving you a 30 us counter. Unfortunately, this crystal frequency is divided down inside the real-time clock chip (or RTC portion of the chipset) such that the processor can only access time in 1 second intervals, IIRC.

I want a register internal to the processor that counts something fast. No win32 API call to a software-updated counter off an ISR (GetTickCount() or QueryPerformanceCounter()), nope, just a raw hardware counter.

/frank
 

MrDudeMan

Lifer
Jan 15, 2001
15,069
94
91
Frank is right. i just did a project regarding this issue, and most motherboards (especially AMD chipsets) use a quartz oscillator. it counts 2^15, or 32,768 times per second. it is done that way because it is VERY easy to count parts of a second or multiple seconds using divide by X counters.
 

DrPizza

Administrator Elite Member Goat Whisperer
Mar 5, 2001
49,601
166
111
www.slatebrookfarm.com
Indirectly related to your question is the concept of Planck time.. there is a smallest amount of time that can be measured. No matter how sophisticated and precise computers get, this is the lower limit for resolution of time.

1.35 x 10^-43 seconds
No smaller division of time has any meaning.
Fortunately, for your question, machine architecture is a LONG way away from this ever being a concern.
 

eigen

Diamond Member
Nov 19, 2003
4,000
1
0
Originally posted by: DrPizza
Indirectly related to your question is the concept of Planck time.. there is a smallest amount of time that can be measured. No matter how sophisticated and precise computers get, this is the lower limit for resolution of time.

1.35 x 10^-43 seconds
No smaller division of time has any meaning.
Fortunately, for your question, machine architecture is a LONG way away from this ever being a concern.

Oh I realize this...I was just adding in a bit of Highly Technical talk so I wouldnt get "wrong forum".. However if time is discrete why does physics treat it like it is continuous...I dont think it should and I think there are models which do this quite well.

Oh I am doing all of this on OSX.
 

DrPizza

Administrator Elite Member Goat Whisperer
Mar 5, 2001
49,601
166
111
www.slatebrookfarm.com
Originally posted by: eigen
Originally posted by: DrPizza
Indirectly related to your question is the concept of Planck time.. there is a smallest amount of time that can be measured. No matter how sophisticated and precise computers get, this is the lower limit for resolution of time.

1.35 x 10^-43 seconds
No smaller division of time has any meaning.
Fortunately, for your question, machine architecture is a LONG way away from this ever being a concern.

Oh I realize this...I was just adding in a bit of Highly Technical talk so I wouldnt get "wrong forum".. However if time is discrete why does physics treat it like it is continuous...I dont think it should and I think there are models which do this quite well.

Oh I am doing all of this on OSX.


Yeah, after I posted, I saw who the original poster was and assumed you knew this as well. My intuition tells me that time is continuous (not that intuitions really matter, particularly at the quantum level).
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |