性能:VC ++比LineTo()API调用上的Builder 5慢33%? [英] Performance: VC++ 33% slower then Builder 5 on LineTo() API call??

查看:70
本文介绍了性能:VC ++比LineTo()API调用上的Builder 5慢33%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候!


直截了当,这是我的实验的结果

。我已将我的评论和问题包括在内了。




时间:

(总时间表示总和每一行的绘图时间。

时间以时钟周期计算(来自QueryPerformanceCounter()API)。

我的<处理器分辨率(QueryPerformanceFrequency()) br />
机器是3579545)。

------------------------------ ------------

Visual Studio .NET 2003

总时间:717230

平均:89.8165625


Borland Builder 5:

总时间:482151

平均:61.0975


代码(对于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句柄);

};


DrawDll.cpp

#include" stdafx。 h"

#include" DrawDll.h"

#include< stdio.h>


BOOL APIENTRY DllMain( HANDLE hModule,

DWORD ul_reason_for_call,

LPVOID lpReserved



{

返回TRUE;

}


void CDrawDll :: MyMethod(HWND句柄)

{


HDC hDC = :: GetDC(句柄);


LARGE_INTEGER m_StartCounter; //开始时间

LARGE_INTEGER m_EndCounter; //完成时间

__int64 m_ElapsedTime;

char buff2 [255];


//适用于800个不同职位
for(int x = 0; x< 800; x ++)

{

//每个位置10次

for(int rep = 0; rep< 10; rep ++)

{

QueryPerformanceCounter(& m_StartCounter);


: :MoveToEx(hDC,x,0,NULL);

:: LineTo(hDC,50 + x,50);


QueryPerformanceCounter(& m_EndCounter );


//获取并存储完成时间和计算经过时间(刻度)

m_2ElapsedTime =(m_2EndCounter.QuadPart -

m_2StartCounter.QuadPart);

sprintf(buff2,"%d \ n",m_2ElapsedTime);

OutputDebugString(buff2);

}

}


ReleaseDC(句柄,hDC);


}

CDrawDll :: CDrawDll()

{

返回;

}


解释

------------------------------------ ---------------------


在从大型项目到Visual Studio的翻译过程中,我开始

面临一些性能问题。在VS编译

可执行文件时,情况要慢得多。我去研究究竟发生了什么,得到了一些

盯着(我的观点)的结论。


我制作了一个DLL并编译了它Builder和Visual C ++ .NET,为两个编译器启用了所有

优化。 DLL有一个只有一个函数的类,它有一个DC的句柄,并在其上绘制8.000行。


我制作了2个可运行的可执行文件来自DLL的函数(也用

两个编译器编译)。


对我来说结果是惊人的,我想要一个解释

发生了什么。


我已经多次运行测试,结果总是相同的

。怎么可能呢,如果我唯一要做的就是MoveTo()和

LineTo()API调用?


这是什么东西简单!我不是在玩磁盘,加载大量的内存,使用托管扩展(我在VS下创建了一个''纯''Win32

项目),任何可能与性能有关的事情。

只有2个简单的API调用。


Visual C ++真的慢得多吗?


我在这里有完整的代码和已编译的可执行文件,并且很高兴

发送给想要复制测试的任何人。至于这个帖子

关注:


- VS编译的DLL和/或可执行文件本身就慢了,对于

实例,Builder 5?

- 为什么简单的API调用需要更长的时间?这不是同一个API调用吗?

难道不应该快速调用API函数本身需要更长的时间吗?

- 有什么我可以做的/尝试让代码运行得更快?


我们想要为Visual C ++迁移其他大项目,但现在我们已经 b $ b了>
第二个想法!


等待光明,

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

推荐答案

你能给我一个例子,说明我什么时候想要在紧凑的循环中调用该函数8000

次?


Jonathan


" Gustavo L. Fabro" <顾************************ @ hotmail.com>在消息中写道

news:34 ************* @ individual.net ...
Could you give me an example of when I would want to call that function 8000
times in a tight loop?

Jonathan

"Gustavo L. Fabro" <gu************************@hotmail.com> wrote in message
news:34*************@individual.net...
问候!

时间安排:
(总时间是指每一行的绘图时间总和。
时间以时钟周期计算(来自QueryPerformanceCounter()API)。
我的
机器的处理器分辨率(QueryPerformanceFrequency())是3579545)。
-------- ----------------------------------
Visual Studio .NET 2003
总时间: 717230
平均分:89.8165625

Borland Builder 5:
总时间:482151
平均值:61.0975

代码(适用于DLL) :
------------------------------------------
DrawDll.h
#ifdef DRAWDLL_EXPORTS
#define DRAWDLL_API __declspec(dllexport)
#else
#define DRAWDLL_API __declspec(dllimport)
#endif

class DRAWDLL_API CDrawDll {
公开:
CDrawDll(void);
void MyMethod(HWND句柄);
};

DrawDll.cpp
#include" stdafx.h"
#include" DrawD ll.h"
#include< stdio.h>

BOOL APIENTRY DllMain(HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved

{
返回TRUE;
}

void CDrawDll :: MyMethod(HWND句柄)


HDC hDC =: :GetDC(句柄);

LARGE_INTEGER m_StartCounter; //开始时间
LARGE_INTEGER m_EndCounter; //完成时间
__int64 m_ElapsedTime;
char buff2 [255];

//对于800个不同的位置
for(int x = 0; x< 800; x ++)
//每个位置10次
for(int rep = 0; rep< 10; rep ++)
{QueryPerformanceCounter(& m_StartCounter) ;

:: MoveToEx(hDC,x,0,NULL);
:: LineTo(hDC,50 + x,50);

QueryPerformanceCounter(& ; m_EndCounter);

//获取并存储完成时间和计算经过时间(刻度)
m_2ElapsedTime =(m_2EndCounter.QuadPart -
m_2StartCounter.QuadPart);
sprintf(buff2,"%d \ n",m_2ElapsedTime);
OutputDebugString(buff2);
}


ReleaseDC(句柄,hDC);



CDrawDll :: CDrawDll()
{
返回;
}

解释
----------------------------------------------- ----------

在从大项目到V的翻译过程中isual Studio,我开始面对一些性能问题。在VS
编译的可执行文件中,事情要慢得多。我去研究究竟发生了什么,并得到一些
凝视(我的观点)结论。

我制作了一个DLL并在Builder和Visual C ++ .NET上编译它,为两个编译器启用了所有
优化。 DLL有一个只有一个函数的类,它获取DC的句柄并在其上绘制8.000行。

我制作了2个可执行文件来运行DLL中的函数(使用
两个编译器也是如此。

结果令人惊讶,对我来说,我想要解释发生了什么。

我已经多次进行测试,结果总是相同的。怎么可能呢,如果我唯一要做的就是MoveTo()
和/或LINETo()API调用?

这很简单!我不是在玩磁盘,加载大量的内存,使用托管扩展(我在VS下创建了一个''纯''Win32
项目),任何与性能有关的东西。只有2个简单的API调用。

Visual C ++真的慢得多吗?

我在这里有完整的代码和编译的可执行文件,很高兴
发送给任何想要复制测试的人。至于这个帖子
是关注的:

- VS编译的DLL和/或可执行文件本身就比较慢,对于
实例,Builder 5?
- 为什么一个简单的API调用需要更长的时间?这不是同一个API
电话吗?
呼叫不应该快,API函数本身需要更长的时间吗?
- 有什么我可以做/尝试做的代码运行得更快?

我们想迁移Visual C ++的其他大项目,但现在我们已经有了第二个想法了!

等待光明,

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



Gustavo L. Fabro写道:
Gustavo L. Fabro wrote:
问候!

直截了当地说,这是我实验的结果。我已将他的意见和问题包括在内了。

时间安排:
(总时间是指每一行的绘图时间总和。
时间以时钟周期计算(来自QueryPerformanceCounter()API)。
我的
机器的处理器分辨率(QueryPerformanceFrequency())是3579545)。
-------- ----------------------------------
Visual Studio .NET 2003
总时间: 717230
平均分:89.8165625

Borland Builder 5:
总时间:482151
平均分:61.0975
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




你看过两个编译器生产的组件吗?


但是这样的人工测试在实际应用中很少有意义......


-

Phil Frisbie,Jr。

Hawk Software
http://www.hawksoft.com



Did you look at the assembly produced by both compilers?

But artificial tests like this rarely mean anything in real applications...

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com


你能给我一个examp当我想要在紧密的循环中调用该函数时,我想要什么?


例如,在CAD应用程序中。该功能只被调用一次,

它做什么

抽取8000行。


在常规CAD绘图上

完成

绘图需要超过8.000行。

Jonathan

" Gustavo L. Fabro <顾************************ @ hotmail.com>在
消息新闻中写道:34 ************* @ individual.net ...
Could you give me an example of when I would want to call that function
8000
times in a tight loop?
In a CAD application, for instance. The function is only called one time,
what it does
is draw 8000 lines.

On a regular CAD drawing much more then 8.000 lines are needed for the
complete
drawing to take place.

Jonathan

"Gustavo L. Fabro" <gu************************@hotmail.com> wrote in
message news:34*************@individual.net...
问候!

直截了当到了这一步,这是我实验的结果。我已将他的意见和问题包括在内了。

时间安排:
(总时间是指每一行的绘图时间总和。
时间以时钟周期计算(来自QueryPerformanceCounter()API)。
我的
机器的处理器分辨率(QueryPerformanceFrequency())是3579545)。
-------- ----------------------------------
Visual Studio .NET 2003
总时间: 717230
平均分:89.8165625

Borland Builder 5:
总时间:482151
平均值:61.0975

代码(适用于DLL) :
------------------------------------------
DrawDll.h
#ifdef DRAWDLL_EXPORTS
#define DRAWDLL_API __declspec(dllexport)
#else
#define DRAWDLL_API __declspec(dllimport)
#endif

class DRAWDLL_API CDrawDll {
公开:
CDrawDll(void);
void MyMethod(HWND句柄);
};

DrawDll.cpp
#include" stdafx.h"
#include" DrawD ll.h"
#include< stdio.h>

BOOL APIENTRY DllMain(HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved

{
返回TRUE;
}

void CDrawDll :: MyMethod(HWND句柄)


HDC hDC =: :GetDC(句柄);

LARGE_INTEGER m_StartCounter; //开始时间
LARGE_INTEGER m_EndCounter; //完成时间
__int64 m_ElapsedTime;
char buff2 [255];

//对于800个不同的位置
for(int x = 0; x< 800; x ++)
//每个位置10次
for(int rep = 0; rep< 10; rep ++)
{QueryPerformanceCounter(& m_StartCounter) ;

:: MoveToEx(hDC,x,0,NULL);
:: LineTo(hDC,50 + x,50);

QueryPerformanceCounter(& ; m_EndCounter);

//获取并存储完成时间和计算经过时间(刻度)
m_2ElapsedTime =(m_2EndCounter.QuadPart -
m_2StartCounter.QuadPart);
sprintf(buff2,"%d \ n",m_2ElapsedTime);
OutputDebugString(buff2);
}


ReleaseDC(句柄,hDC);



CDrawDll :: CDrawDll()
{
返回;
}

解释
----------------------------------------------- ----------

在从大项目到V的翻译过程中isual Studio,我开始面对一些性能问题。在VS
编译的可执行文件中,事情要慢得多。我去研究究竟发生了什么,并得到一些
凝视(我的观点)结论。

我制作了一个DLL并在Builder和Visual C ++ .NET上编译它,为两个编译器启用了所有
优化。 DLL有一个只有一个函数的类,它获取DC的句柄并在其上绘制8.000行。

我制作了2个可执行文件来运行DLL中的函数(使用
两个编译器也是如此。

结果令人惊讶,对我来说,我想要解释发生了什么。

我已经多次进行测试,结果总是相同的。怎么可能呢,如果我唯一要做的就是MoveTo()
和/或LINETo()API调用?

这很简单!我不是在玩磁盘,加载大量的内存,使用托管扩展(我在VS下创建了一个''纯''Win32
项目),任何与性能有关的东西。只有2个简单的API调用。

Visual C ++真的慢得多吗?

我在这里有完整的代码和编译的可执行文件,很高兴
发送给任何想要复制测试的人。至于这个帖子
是关注的:

- VS编译的DLL和/或可执行文件本身就比较慢,对于
实例,Builder 5?
- 为什么一个简单的API调用需要更长的时间?这不是同一个API
电话吗?
呼叫不应该快,API函数本身需要更长的时间吗?
- 有什么我可以做/尝试做的代码运行得更快?

我们想迁移Visual C ++的其他大项目,但现在我们已经有了第二个想法了!

等待光明,

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




这篇关于性能:VC ++比LineTo()API调用上的Builder 5慢33%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆