对于数学,C#与C ++的速度差异为30%? [英] 30% difference in speedof C# vs C++ for math?

查看:69
本文介绍了对于数学,C#与C ++的速度差异为30%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用C#来开发一个科学应用程序,但是我已经注意到在同一台机器上VC ++ .NET和C#之间有30%的差异,

下相同条件:


double a = 0,b = 0,c = 0,d = 0,e = 0;

for(int n = 0 ; n!= 6000000; n ++)

{

a = n%5 * 2/3 - 4 + 6/3 - n + n * 2;

b = n * 2.3 - 1 * 2/3 - 4 + 6/3 - n + n * 2;

c = n * 3 / 3.5 * 2/3 - 4 + 6 / 3 - n + n * 2;

d = n + 1 * 2 * 2/3 - 4 + 6/3 - n + n * 2;

e = n / 2 * 2/3 - 4 + 6/3 - n + n * 2;

}


VB.NET需要2300ms,C#需要1000ms VC ++中只有700ms


这听起来不错吗?


谢谢。

Richard

解决方案

你是否在发布版本中构建了?

你是否在构建过程中打开了优化参数?

VC ++代码是原生的还是托管的?


所有这些都会影响性能。




< re ***** @ gmail。 COM>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...

你是否在发布版本中构建了?
你是否在构建过程中打开了优化参数?
是VC ++代码本机还是托管?

所有这些都将影响性能。




1.两者都在发布模式下运行(C#和VC ++)。

2. VC ++程序已经过优化速度。我找不到类似的

选项C#

3. VC ++代码是原生的。


有没有选项可以在编译的C#应用​​程序中最大化速度?


Richard


理查德,


如果您需要这种速度,请购买数学组件(以及一个特定于您的应用程序类型的b $ b)并使用C#开发GUI

和业务逻辑。这比用C ++写一切

更有意义。


最好的问候

Johann Blake

I was considering C# for developing a scientific application, but I have
noticed a ~30% difference between VC++ .NET and C# on the same machine,
under identical conditions:

double a = 0,b = 0, c = 0, d = 0, e = 0;
for(int n = 0; n != 6000000; n++)
{
a = n % 5 *2 / 3 - 4 + 6 / 3 - n + n * 2;
b = n * 2.3 - 1 *2 / 3 - 4 + 6 / 3 - n + n * 2;
c = n * 3 / 3.5 *2 / 3 - 4 + 6 / 3 - n + n * 2;
d = n + 1 * 2 *2 / 3 - 4 + 6 / 3 - n + n * 2;
e = n / 2 *2 / 3 - 4 + 6 / 3 - n + n * 2;
}

It takes 2300ms in VB.NET, 1000ms in C# but only 700ms in VC++

Does this sound right?

Thanks.
Richard

解决方案

did you build in release version?
did you open the optimizing parameter in the building process?
is the VC++ code native or managed?

all of these will affect the performance.



<re*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...

did you build in release version?
did you open the optimizing parameter in the building process?
is the VC++ code native or managed?

all of these will affect the performance.



1. Both were run in Release mode (C# and VC++).
2. The VC++ program was optimized for speed. I could not find a similar
option for C#
3. The VC++ code is native.

Is there an option to maximize speed in a compiled C# application?

Richard


Richard,

If you need that kind of speed, buy a math component (and one
particular to your type of application) and use C# to develop the GUI
and business logic. That makes far more sense than writing everything
in C++.

Best Regards
Johann Blake


这篇关于对于数学,C#与C ++的速度差异为30%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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