Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / February 2005

Tip: Looking for answers? Try searching our database.

timing performance of code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ronny - 27 Feb 2005 15:33 GMT
Hi

I am looking to time the performance of my code, I am currently using the
system time "DateTime::Now" however I am finding the results are not very
accurate.

I have been told that I can use the system diagnostics to use a performance
counter. However I have not been able to get any code that relates to
C++.net (managed).

Can anyone help me get started?
Carl Daniel [VC++ MVP] - 27 Feb 2005 15:42 GMT
> Hi
>
[quoted text clipped - 7 lines]
>
> Can anyone help me get started?

You can just use the native
QueryPerformanceCounter/QueryPerformanceFrequency Win32 functions from
managed C++.  If you'd rather not #include <windows.h>, you could just
declare them:

#pragma unmanaged

extern "C"
{
   int __stdcall QueryPerformanceCounter(__int64* p);
   int __stdcall QueryPerformanceFrequency(__int64* p);
}

#pragma managed

To use them, call QueryPerformanceCounter at the start and end of your code
block.  Call QueryPerformanceFrequency once to determine the resolution of
the counts.

__int64 start;
__int64 end;
::QueryPerformanceCounter(&start);
//
// Your code to be measured here
//
::QueryPerformanceCounter(&end);

__int64 freq;
::QueryPerformanceFrequency(&freq);
double elapsedSeconds = double(end-start)/freq;

HTH

-cd
ronny - 27 Feb 2005 17:35 GMT
Thanks for your reply Carl. I have tried to add the code you suggested but I
get the following errors

...Include\WinBase.h(9839): error C2733: second C linkage of overloaded
function 'QueryPerformanceCounter' not allowed
...Include\WinBase.h(9846): error C2733: second C linkage of overloaded
function 'QueryPerformanceFrequency' not allowed
...WinBase.h(9844) : see declaration of 'QueryPerformanceFrequency'

I'm not sure if I have added the code to the correct place. My "Form1.h"
looks like this.

***********************************************
#pragma unmanaged
extern "C"
{
   int __stdcall QueryPerformanceCounter(__int64* p);
   int __stdcall QueryPerformanceFrequency(__int64* p);
}

#pragma managed
#include <stdio.h>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
......
**********************************************

Ronny

>> Hi
>>
[quoted text clipped - 42 lines]
>
> -cd
Carl Daniel [VC++ MVP] - 27 Feb 2005 17:46 GMT
> Thanks for your reply Carl. I have tried to add the code you
> suggested but I get the following errors
[quoted text clipped - 4 lines]
> overloaded function 'QueryPerformanceFrequency' not allowed
> ...WinBase.h(9844) : see declaration of 'QueryPerformanceFrequency'

Just get rid of the re-definition of the functions - you've obviously
already included <windows.h>.

-cd
Carl Daniel [VC++ MVP] - 27 Feb 2005 18:47 GMT
>> Thanks for your reply Carl. I have tried to add the code you
>> suggested but I get the following errors
[quoted text clipped - 7 lines]
> Just get rid of the re-definition of the functions - you've obviously
> already included <windows.h>.

... and you'll have to use LARGE_INTEGER (look it up) instead of __int64.

-cd
ronny - 28 Feb 2005 11:16 GMT
Ok, i've got it working fine now. Thanks for your help.

>>> Thanks for your reply Carl. I have tried to add the code you
>>> suggested but I get the following errors
[quoted text clipped - 11 lines]
>
> -cd
Ioannis Vranos - 28 Feb 2005 14:13 GMT
> Ok, i've got it working fine now. Thanks for your help.

Perhaps you are looking for a .NET profiler? Here is a free one:

http://www.microsoft.com/downloads/details.aspx?FamilyId=86CE6052-D7F4-4AEB-9B7A
-94635BEEBDDA&displaylang=en


It displays time-costs and everything.

And two videos about how to use it:

http://www.microsoft.com/downloads/details.aspx?FamilyId=CD5AA57C-9CD1-45AB-AA4B
-8DC586D30938&displaylang=en


Signature

Ioannis Vranos


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.