Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using GetLocalTime in my code to check how much time the perticular function is taking for processing.

For this purpose which one is the best choice GetLocalTime or GetSystemTime ?

Are they same ? which one should be used if i am measuring the performance of the code.


Thanks in advance.
Posted

[Answering a follow-up question]

As this is C++/CLI, you can use .NET libraries. For performance measuring, use the class System.Diagnostics.Stopwatch as it has much better accuracy (sub-microsecond on most systems). You can inquire if the high resolution operation is accessible and the implemented frequency by calling static properties System.Diagnostics.Stopwatch.IsHighResolution and System.Diagnostics.Stopwatch.Frequency. See http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx[^].

—SA
 
Share this answer
 
v2
Comments
Espen Harlinn 20-Jul-11 19:08pm    
Stopwatch is definitely the best solution provided by .Net - my 5
Sergey Alexandrovich Kryukov 20-Jul-11 22:03pm    
I think you brought to my attention much better resolution of this class a while ago -- thank you very much.
--SA
GetLocalTime gives you time based on current timezone.
GetSystemTime is the system time and has nothing to do with timezone.
 
Share this answer
 
Comments
PrafullaVedante 19-Jul-11 2:58am    
Which one should i use to measure the performance ?
CPallini 19-Jul-11 3:08am    
As far as you use them consistently (i.e. always the same) it doesn't matter, since performance is measured using time intervals, i.e. time differences (however, if you're using Windows, maybe QueryPerformanceCounter would be better for the purpose).
PrafullaVedante 19-Jul-11 4:12am    
Thanks for the suggession. I am using it , but the problem is how to write it to the file, as it takes __int64 as an output parameter
Sergey Alexandrovich Kryukov 20-Jul-11 0:52am    
It's System.Diagnostics.Stopwatch, please see my answer.
--SA
Sergey Alexandrovich Kryukov 20-Jul-11 0:53am    
Answered, my 5. OP ***real*** question was about timing for performance measuring, so the answer is "neither". Please see my solution.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900