关于性能,是不是我写错了,竟然差这么多
认为Delphi性能比C#好,于是打算做成DLL让C#调用,但只是"认为"没有数据,性能好多少,数据为准,于是有了下面的测试
C# 页面,分别用C#和调用Delphi的DLL和调用C++的DLL
======================================
int k = 999999999;
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
int i;
for (i = 0; i < k; i++) ;
sw.Stop();
Response.Write( "<br />#:" + i.ToString() + ":" + sw.ElapsedMilliseconds.ToString() );
System.Diagnostics.Stopwatch sw3 = new System.Diagnostics.Stopwatch();
sw3.Start();
i = VC_test(k);
sw3.Stop();
Response.Write("<br />C:" + i.ToString() + ":" + sw3.ElapsedMilliseconds.ToString());
System.Diagnostics.Stopwatch sw2 = new System.Diagnostics.Stopwatch();
sw2.Start();
i = Del_test(k);
sw2.Stop();
Response.Write("<br />D:" + i.ToString() + ":" + sw2.ElapsedMilliseconds.ToString());
Delphi代码如下:
================================
library Project2;
function Del_test(i: integer):integer;stdcall;
var
j: integer;
begin
for j:=0 to i do;
result:=j;
end;
exports
Del_test;
begin
end.
VC代码如下:
===================================
extern "C"__declspec(dllexport)int _stdcall VC_test(int init);
int _stdcall VC_test(int init){
int i;
for(i=0;i<=init;i++);
return i;
}
测试结果如下:
===================================
#:999999999:3747
C:1000000000:10
D:1000000000:485
C++ 跟 Delphi怎么差这么多啊??我一直钟爱Delphi的,哪个地方错了啊,太失望了!!
另外说一点,我是刷新了好几下,结果的数字都差不多,所以随便取了一组,没有求平均值