G
Gustavo L. Fabro
Greetings!
Getting straight to the point, here are the results
of my experiment. I've included my comments and questions
after them.
The timing:
(The total time means the sum of each line's drawing time.
Time is measured in clock ticks (from QueryPerformanceCounter() API).
The processor resolution (QueryPerformanceFrequency()) for my
machine is 3579545).
------------------------------------------
Visual Studio .NET 2003
Total time: 717230
Average: 89.8165625
Borland Builder 5:
Total Time: 482151
Average: 61.0975
The code (for the DLL):
------------------------------------------
DrawDll.h
#ifdef DRAWDLL_EXPORTS
#define DRAWDLL_API __declspec(dllexport)
#else
#define DRAWDLL_API __declspec(dllimport)
#endif
class DRAWDLL_API CDrawDll {
public:
CDrawDll(void);
void MyMethod(HWND handle);
};
DrawDll.cpp
#include "stdafx.h"
#include "DrawDll.h"
#include <stdio.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
void CDrawDll::MyMethod(HWND handle)
{
HDC hDC = ::GetDC(handle);
LARGE_INTEGER m_StartCounter; // start time
LARGE_INTEGER m_EndCounter; // finish time
__int64 m_ElapsedTime;
char buff2[255];
//For 800 different positions
for(int x=0;x<800;x++)
{
//10 times on each position
for(int rep=0;rep<10;rep++)
{
QueryPerformanceCounter (&m_StartCounter);
::MoveToEx(hDC, x,0, NULL);
::LineTo(hDC, 50+x,50);
QueryPerformanceCounter (&m_EndCounter);
//get and store finishing time and calc elapsed time(ticks)
m_2ElapsedTime = (m_2EndCounter.QuadPart -
m_2StartCounter.QuadPart );
sprintf(buff2, "%d\n", m_2ElapsedTime);
OutputDebugString(buff2);
}
}
ReleaseDC(handle, hDC);
}
CDrawDll::CDrawDll()
{
return;
}
The explanation
---------------------------------------------------------
In the translation process from a big project to Visual Studio, I started
facing some performance problems. Things were much slower on the VS compiled
executables. I went to study what exactly was happening and got to some
staring (to my point of view) conclusions.
I made a DLL and compiled it on Builder and Visual C++ .NET, with all
optimizations enabled for both compilers. The DLL has a class with only
one function, that gets a handle for a DC and draws 8.000 lines on it.
I made 2 executables that run the function from the DLL (compiled with
both compilers too).
The results were astonishing, for me, and I'd like an explanation for
what is happening.
I've run the test several times and the results are always of the
same magnitude. How can that be, if the only thing I'm doing is MoveTo() and
LineTo() API calls?
It's something simple! I'm not playing with the disk, loading large
chunks of memory, using managed extensions (I created a 'pure' Win32
project under VS), anything that could relate with performance.
Only 2 simple API calls.
Is Visual C++ really THAT MUCH slower?
I have the complete code and compiled executables here and will be glad
to send to anyone who wants to replicate the test. As for this posting
is concerned:
- Is VS compiled DLLs and/or executables inherently slower then, for
instance, Builder 5?
- Why does a simple API call takes that longer? Isn't it the same API call?
Shouldn't the call be fast and the API function itself take longer?
- Is there anything I can do/try to make the code run faster?
We would like to migrate other big projects for Visual C++, but now we're
having
second thoughts!
Waiting for a light,
Gustavo L. Fabro
Getting straight to the point, here are the results
of my experiment. I've included my comments and questions
after them.
The timing:
(The total time means the sum of each line's drawing time.
Time is measured in clock ticks (from QueryPerformanceCounter() API).
The processor resolution (QueryPerformanceFrequency()) for my
machine is 3579545).
------------------------------------------
Visual Studio .NET 2003
Total time: 717230
Average: 89.8165625
Borland Builder 5:
Total Time: 482151
Average: 61.0975
The code (for the DLL):
------------------------------------------
DrawDll.h
#ifdef DRAWDLL_EXPORTS
#define DRAWDLL_API __declspec(dllexport)
#else
#define DRAWDLL_API __declspec(dllimport)
#endif
class DRAWDLL_API CDrawDll {
public:
CDrawDll(void);
void MyMethod(HWND handle);
};
DrawDll.cpp
#include "stdafx.h"
#include "DrawDll.h"
#include <stdio.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
void CDrawDll::MyMethod(HWND handle)
{
HDC hDC = ::GetDC(handle);
LARGE_INTEGER m_StartCounter; // start time
LARGE_INTEGER m_EndCounter; // finish time
__int64 m_ElapsedTime;
char buff2[255];
//For 800 different positions
for(int x=0;x<800;x++)
{
//10 times on each position
for(int rep=0;rep<10;rep++)
{
QueryPerformanceCounter (&m_StartCounter);
::MoveToEx(hDC, x,0, NULL);
::LineTo(hDC, 50+x,50);
QueryPerformanceCounter (&m_EndCounter);
//get and store finishing time and calc elapsed time(ticks)
m_2ElapsedTime = (m_2EndCounter.QuadPart -
m_2StartCounter.QuadPart );
sprintf(buff2, "%d\n", m_2ElapsedTime);
OutputDebugString(buff2);
}
}
ReleaseDC(handle, hDC);
}
CDrawDll::CDrawDll()
{
return;
}
The explanation
---------------------------------------------------------
In the translation process from a big project to Visual Studio, I started
facing some performance problems. Things were much slower on the VS compiled
executables. I went to study what exactly was happening and got to some
staring (to my point of view) conclusions.
I made a DLL and compiled it on Builder and Visual C++ .NET, with all
optimizations enabled for both compilers. The DLL has a class with only
one function, that gets a handle for a DC and draws 8.000 lines on it.
I made 2 executables that run the function from the DLL (compiled with
both compilers too).
The results were astonishing, for me, and I'd like an explanation for
what is happening.
I've run the test several times and the results are always of the
same magnitude. How can that be, if the only thing I'm doing is MoveTo() and
LineTo() API calls?
It's something simple! I'm not playing with the disk, loading large
chunks of memory, using managed extensions (I created a 'pure' Win32
project under VS), anything that could relate with performance.
Only 2 simple API calls.
Is Visual C++ really THAT MUCH slower?
I have the complete code and compiled executables here and will be glad
to send to anyone who wants to replicate the test. As for this posting
is concerned:
- Is VS compiled DLLs and/or executables inherently slower then, for
instance, Builder 5?
- Why does a simple API call takes that longer? Isn't it the same API call?
Shouldn't the call be fast and the API function itself take longer?
- Is there anything I can do/try to make the code run faster?
We would like to migrate other big projects for Visual C++, but now we're
having
second thoughts!
Waiting for a light,
Gustavo L. Fabro