问题描述
在Visual Studio C / C ++项目,可以很容易地修改编译器的优化设置中的属性页| C / C ++ |优化。例如,我们可能会给出不同的优化级别,如/ O2和/ O3,以及像省略帧指针高级优化。
In Visual Studio C/C++ projects, it's easy to modify compiler's optimization settings in "Property Pages | C/C++ | Optimization". For example, we may give different optimization levels such as /O2 and /O3, as well as advanced optimizations like "Omit Frame Pointers".
不过,我不能简单地找到相应的用户界面在C#项目的Visual Studio。所有我能找到的仅仅是关闭的优化:优化code复选框是我的一切。
However, I can't simply find corresponding UIs in C# project of Visual Studio. All I can find is just turning off optimizations: the "Optimize code" check box is all I've got.
CAN C#的用户控制详细的编译器的优化,如C / C ++?我必须给编译器选项在命令行?
Can C# users control detailed compiler's optimizations like C/C++? Do I have to give compiler options in command line?
推荐答案
大部分的C#code优化的推移,在JIT编译器的水平,而不是C#编译器。基本上有没有这样详细的设置在C或C可用的那些++。
Much of the optimisation of C# code goes on at the JIT compiler level, rather than the C# compiler. Basically there are no such detailed settings as the ones available in C or C++.
有运行时的一些性能相关的元素,可以进行调整,如GC策略,但不是很大。
There are a few performance-related elements of the runtime that can be tweaked, such as GC strategies, but not a great deal.
当我建立基准测试等命令行我倾向于只使用这样的:
When I'm building benchmark tests etc from the command line I tend to just use something like this:
csc /o+ /debug- Test.cs
(我的相信的我看到了一个匹配的PDB文件的presence有所作为的表现,可能在异常的成本方面被抛出,因此调试 -
开关...但我可能是错的)
(I believe I have seen the presence of a matching pdb file make a difference to performance, possibly in terms of the cost of exceptions being thrown, hence the debug-
switch... but I could be wrong.)
编辑:如果你想看到最优化的每一位产生差别,有可能证明有趣的方法:
If you want to see the difference each bit of optimization makes, there's one approach which could prove interesting:
- 编译相同的code有和没有优化
- 使用在IL模式ILDASM或反思,看看有什么区别
- 应用在相同时间的变化之一手动(使用ILASM),测量有多少每个人都有
这篇关于我在哪里可以在Visual Studio中修改详细的C#编译器的优化设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!