473,396 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Timing function call

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!
Oct 11 '06 #1
3 1598
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/micro...3c2bcaba6ff09c
)

"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.

--
Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"
"eladla" wrote:
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!
Oct 11 '06 #2
"Bruno van Dooren [MVP VC++]" <br**********************@hotmail.comwrote
in message news:96**********************************@microsof t.com...
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/micro...3c2bcaba6ff09c
)

"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
Oct 11 '06 #3
Worked like a charme.
Thank you.
Oct 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Russell | last post by:
I have a quirky issue that I believe involves timing and only 2 hairs left to pull. I have a modal dialog that is an IFrame. The IFrame contains another window - which contains the appropriate...
4
by: rvandervort | last post by:
I'm having a real problem here. I have a JS function: getExpenseDetails() it's a asynch call to a php script behind the scenes which returns XML formatted expense details. in my onreadystate...
10
by: Greg Stark | last post by:
This query is odd, it seems to be taking over a second according to my log_duration logs and according to psql's \timing numbers. However explain analyze says it's running in about a third of a...
7
by: Droopy | last post by:
Hi, I don't understand why sometimes, a loop running in a thread takes much more time than usual. I have a thread that must call each 20 ms a C++ unmanaged function. I made a C++ managed...
7
by: jamie | last post by:
hey all, I am attempting to do motion control for a final project, but I have a concern.... For motion control, timing is everyting, the better it is, the better it works. Currently I am...
7
by: Steven D'Aprano | last post by:
I have two code snippets to time a function object being executed. I expected that they should give roughly the same result, but one is more than an order of magnitude slower than the other. ...
2
by: Steven D'Aprano | last post by:
The timeit module is ideal for measuring small code snippets; I want to measure large function objects. Because the timeit module takes the code snippet argument as a string, it is quite handy...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
2
by: kevin | last post by:
Hi... I'm having a few problems here... I want to input in my function different values and then time each one to see how long it took to run the function... so right now it doesn't like the "i"...
2
by: julie.siebel | last post by:
Google apparently ate my original post to this (grr) so this'll be a bit more vague than the initial post, but...*sigh*. Javascript is not my forte, and I apologize for the acky-ness of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.