Question about tic toc accuracy and how it relates to PC's internal clock

21 views (last 30 days)
I am just wondering about how accurate tic toc actually is. I know on windows, matlab uses the win32 functions QueryPerformanceCounter() and QueryPerformanceFrequency() as the basis for tic toc. I also know that the accuracy of QPC/tic toc is somewhat dependent on the PC hardware, and that QPC isn't synchronized to a NTP or other external source.
From here my knowledge is a bit lacking. I'm assuming that QPC, and consequently tic toc relies on the CPU's XO? In which case is it fair to say that the accuracy of tic toc is directly correlated with the frequency error of a PC's crystal oscillator? And as such it's reasonable to expect the frequency error of tic toc to be somewhere in the ballpark of 20-150ppm (or whatever the avg frequency error range of modern PCs is - I actually have no idea) depending on the quality of the crystal?
Thanks.

Answers (1)

vidyesh
vidyesh on 11 Oct 2023
Hi lachlan,
I understand that you want to know more about the accuracy of the 'tic toc' functions and the factors that influence their precision.
Indeed, the accuracy of tic toc in MATLAB, utilizes the win32 functions QueryPerformanceCounter and QueryPerformanceFrequency on Windows, and does have a certain dependence on the hardware of the PC. Therefore, the precision of tic toc is linked to the frequency error of the CPU's crystal oscillator.
In order to enhance the accuracy of timing measurements, it is advisable to execute the code multiple times within a loop and calculate the average time.
Alternatively, utilizing functions like timeit or profile can provide more precise time measurements.
You can find more details about the 'profile’ and ‘timeit’ functions here:
Refer to this documentation page to learn about the various timing functions.
Hope this answer helps.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!