本文介绍了对于数学,C#与C ++的速度差异为30%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在考虑使用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 解决方案 1.两者都在发布模式下运行(C#和VC ++)。 2. VC ++程序已经过优化速度。我找不到类似的 选项C# 3. VC ++代码是原生的。 有没有选项可以在编译的C#应用程序中最大化速度? Richard I was considering C# for developing a scientific application, but I havenoticed 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 解决方案1. Both were run in Release mode (C# and VC++).2. The VC++ program was optimized for speed. I could not find a similaroption for C#3. The VC++ code is native.Is there an option to maximize speed in a compiled C# application?Richard 这篇关于对于数学,C#与C ++的速度差异为30%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!