Timing function call

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
I have a function in C++/CLI that calls a native C++ function.
I want the C++/CLI function to measure the time between the call to the
unmanaged function and the return to the managed function.

Can anyone point me in the right direction?
I don`t really know where to start and have not found anything on google or
MSDN NGs.

Thanks!
 
You can use the Stopwatch class to do that very easily. See MSDN for more info.

A note of caution if you want to use ns precision:
(From this thread:
http://groups.google.com/group/micr...7c46/6f3c2bcaba6ff09c?&hl=en#6f3c2bcaba6ff09c
)

"One should not use Elapsed.Ticks to calculate the elapsed time in
nanoseconds.
The only correct way to get this high precision count is by using
Stopwatch.ElapsedTicks like this:
long nanosecPerTick = (1000L*1000L*1000L) / Stopwatch.Frequency;
....
long ticks = sw.ElapsedTicks;
Console.WriteLine("{0} nanoseconds", ticks * nanosecPerTick);
or use Stopwatch.ElapsedMiliseconds.
 
Bruno van Dooren said:
You can use the Stopwatch class to do that very easily. See MSDN for more
info.

A note of caution if you want to use ns precision:
(From this thread:
http://groups.google.com/group/micr...7c46/6f3c2bcaba6ff09c?&hl=en#6f3c2bcaba6ff09c
)

"One should not use Elapsed.Ticks to calculate the elapsed time in
nanoseconds.
The only correct way to get this high precision count is by using
Stopwatch.ElapsedTicks like this:

<G> Been there, done that. Brilliant design that Stopwatch.Elapsed.Ticks
and Stopwatch.ElapsedTicks are both valid but have radically different
meanings.

-cd
 
Back
Top