|
Hello everyone,
What is the convenient way to calculate the execution time of a function? The function may be not a long and time consuming function -- only 10 lines in some situation.
thanks in advance,
George
|
|
|
|
|
One of the ways could be to use QueryPerformanceCounter()
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Thank you _AnShUmAn_!
I have tried the method, and the results are in LARGE_INTEGER structure. Do you know how to calculate the difference between two LARGE_INTEGER structure variable (the difference of begin time and complete time)? I have tried to use '-' sign, but there are compiling errors.
regards,
George
|
|
|
|
|
use GetTickCount function before and after the function and take the difference. But it only have a resolution of 15 milliseconds. For high resolution use
QueryPerformanceCounter()
nave
|
|
|
|
|
Thank you nave,
I have tried the method, and the results are in LARGE_INTEGER structure. Do you know how to calculate the difference between two LARGE_INTEGER structure variable (the difference of begin time and complete time)? I have tried to use '-' sign, but there are compiling errors.
regards,
George
|
|
|
|
|
check this
LARGE_INTEGER tBefore, tAfter, iPerfFrequency;
float TimeElapsed;
// to determine how often the performance counter increments
QueryPerformanceFrequency( &iPerfFrequency);
// Get performance counter before the function
QueryPerformanceCounter(&tBefore);
MyFunction() // Call the function for which the performace is to be calculated
QueryPerformanceCounter(&tAfter);
TimeElapsed = tAfter.QuadPart - tBefore.QuadPart;// finding elapsed time
TimeElapsed = TimeElapsed / iPerfFrequency.QuadPart;
cout<
|
|
|
|
|
Thank you nave!
I have tried your code, and it works cool! I have also referenced related MSDN document, and I think your method will print out the elapsed seconds, right?
regards,
George
|
|
|
|
|
|
|
I think better way would be try to find out the Time and space complexity for the function and then use the QueryPerformanceCounter().
Cheers
"Peace of mind through Technology"
|
|
|
|
|
I have tried the method, and the results are in LARGE_INTEGER structure. Do you know how to calculate the difference between two LARGE_INTEGER structure variable (the difference of begin time and complete time)? I have tried to use '-' sign, but there are compiling errors.
regards,
George
|
|
|
|
|
If you are happy to test function times in the IDE, use the profiler - much more convenient and more accurate than other methods.
Look for help on Profiler in MSDN - I have not used it for years, and I remember it can be a pain working out how to activate it. And I had one project where I could not turn it on, no matter what I tried.
|
|
|
|
|
Thank you normanS!
Can you provide a link to the Profiler tool? I have searched "Profiler", but all I can get is SQL related profiler.
regards,
George
|
|
|
|
|
What Visual Studio are you running?
If you say that you are using VS6, I will look on my home PC - I do not have a development environment at work!
(I see you have already received answers that do the job, but learning how to use profiler is worth it anyway!)
-- modified at 5:45 Thursday 15th June, 2006
|
|
|
|
|
Hi normanS,
I am using Visual Studio 2003 (Visual Studio.Net). Do you have any reference URLs for how to use profiler for this version?
regards,
George
|
|
|
|
|
Sorry for the slow reply - Friday was a holiday and I don't check email at home!
I can't help you with the profiler for VS2003. I have only used Visual Studio 6 (and even in VS6, I have difficulty finding the profiler!)
|
|
|
|
|
Thank you all the same man,
I appreciate your comments and ideas in the past.
regards,
George
|
|
|
|
|
If you are using VC++ v6, it's at the bottom of the Build menu. If it's disabled, you'll first need to rebuild the project with profiling information.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thank you DavidCrow!
I am using Visual Studio 2003 (Visual Studio.Net). I have checked that in the Build menu of IDE, there is no items called profiler or something similar.
Do you have any reference materials about how to use profiler in Visual Studio 2003?
regards,
George
|
|
|
|
|
George_George wrote: Do you have any reference materials about how to use profiler in Visual Studio 2003?
No, I do not use that version.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I need to change the text in wizard button of PropertySheet following the language of PropertyPage. I've tried to use PSH_USEPAGELANG(set PSH_USEPAGELANG for dwFlags) but it did not work. Could anyone give me a solution?
Thanks a lot.
adfafafa
|
|
|
|
|
If you have a handle to the button, just use SetWindowText() .
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Dear VC-masters;
A simple problem need your help.
a treeview built in a toolbar in mutil-doc project. while right key happen on the tree notes,I want to creat a pop-menu to operate the treeview, such as add note or del note in the tree.
void CMainFrame::OnRclickTree(NMHDR* pNMHDR, LRESULT* pResult)
{
CMenu dMenu;
if(!dMenu.LoadMenu(IDR_TREERKEY))
{
AfxThrowResourceException();
}
CMenu *pPopupMenu = dMenu.GetSubMenu(0);
ASSERT(pPopupMenu != NULL);
CPoint point;
ScreenToClient(&point) ;
pPopupMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON,point.x,point.y,AfxGetMainWnd());
}
1>how can I get current mouse position?
2>the add and del note command?
|
|
|
|
|
zeus_master wrote: 1>how can I get current mouse position?
::GetCursorPos(LPPOINT) The cursor position is always specified in screen coordinates so use ScreenToClient to convert to client coordinates.
Nibu thomas
A Developer
Programming tips[^] My site[^]
|
|
|
|
|
zeus_master wrote: 1>how can I get current mouse position?
use GetCurrentMessage() funtion. it will return a structure of MSG. The MSG contains a member that holds the point in which the last message occured.
U can also GetCursorPos() to get mouse the position. But I prefer the first one. Also I think there is no need to call ScreenToClient(&point) .
zeus_master wrote: 2>the add and del note command?
I didn't understand this
nave
|
|
|
|