I am trying to implement a high resolution timer in C# with VS 2008.
I have found two websites with code examples here:
http://www.codeproject.com/KB/cs/highperformancetimercshar.aspx
http://www.cambiaresearch.com/c4/803908d2-ab13-4b90-9d73-6c940e70d9bd/csharp-StopWatch-Class.aspx
I should mention that I never used VS studio or C# which may explain my questions.
The provide code does work, however what I need is a series of time points through my code such as were part1 begins and ends, part 2 begins and ends and so on and so I can measure the time between any of the different sections.
I though of adding a method to the class that returns the frequency and the time at any point and have my code calculate all the time differences internally.
Do I need to keep it in a class? Meaning can I call the performance counter directly from my code?
They both use DLLImport("Kernel32.dll") is that how the functions are initialized?
Also, the first site gives the time in seconds, while the second one says the result is in tens of milliseconds and multiplies it by 10000. Which one is correct?
My machine is 2.66 GHz and the frequency is about 2.66 billion, so I would think the first way is correct.
Also, if I replace the frequency in my code to 1/fequency and multiply, will I loose precision, and will the performance improvement be work it?
I know there is overhead with the performance timer, is there a known range as to how many cycles it takes to give the result.
Sorry for all these questions. I would greatly appreciate any help I can get.
Thank you,
elkinm
I have found two websites with code examples here:
http://www.codeproject.com/KB/cs/highperformancetimercshar.aspx
http://www.cambiaresearch.com/c4/803908d2-ab13-4b90-9d73-6c940e70d9bd/csharp-StopWatch-Class.aspx
I should mention that I never used VS studio or C# which may explain my questions.
The provide code does work, however what I need is a series of time points through my code such as were part1 begins and ends, part 2 begins and ends and so on and so I can measure the time between any of the different sections.
I though of adding a method to the class that returns the frequency and the time at any point and have my code calculate all the time differences internally.
Do I need to keep it in a class? Meaning can I call the performance counter directly from my code?
They both use DLLImport("Kernel32.dll") is that how the functions are initialized?
Also, the first site gives the time in seconds, while the second one says the result is in tens of milliseconds and multiplies it by 10000. Which one is correct?
My machine is 2.66 GHz and the frequency is about 2.66 billion, so I would think the first way is correct.
Also, if I replace the frequency in my code to 1/fequency and multiply, will I loose precision, and will the performance improvement be work it?
I know there is overhead with the performance timer, is there a known range as to how many cycles it takes to give the result.
Sorry for all these questions. I would greatly appreciate any help I can get.
Thank you,
elkinm