Performance: Compile in VS, Run in Mono on Windows and Linux

元气小坏坏 提交于 2019-12-24 00:20:49

问题


I have the following questions:

  1. Is it possible to compile a C# project using VS.NET, and run it on mono?
  2. Are there any performance benefits associated with approach 1 (vs compiling with the mono compiler)?
  3. What about running the output .exe/.dll on linux? And what are the associated performance characteristics?

Thanks


回答1:


  1. Yes, you can do that. It should work unless the code uses some framework elements that are not implemented on mono.

  2. Not that I am aware of.

  3. Not sure what the difference between #3 and #1 is. If you are referring to using mono to compile on Windows, then porting it to linux, it should still work the same. Both compilers generate essentially the same IL code.




回答2:


1:
Yes. The compilers compile into IL code, which runs in either system.

Not every library is implemented in Mono, but those that are should work seamlessly. Also, the code has to be written to be independend of the system to work properly, for example:

  • Use Path.DirectorySeparatorChar and Path.Combine to form file paths, instead of using the string literal "\" or "/".
  • Use the BitConverter class to do byte manipulation that is independend of big-endian / little-endian achitecture.

2:
There may be some differences in what code the compilers generate, but as almost all optimising is done by the JIT compiler that should rarely make any measurable difference.

3:
The exe and dll files does not contain native code, they contain IL code. The native code is generated by the JIT compiler when the exe/dll is loaded.




回答3:


To expand on others answers:

For point 3. Yes there will be a performance difference when using MSCLR vs Mono, and no, I don't know what it will be. Maybe nothing, maybe little or perhaps one is vastly faster - you'll have to profile your specific application.

Note also, that notwithstanding the speed of the code made by the JIT compiler, the libraries will be implemented very differently and will almost certainly have varying performance characteristics.

If you plan on supporting your application under Mono, you will need to run performance testing there as well as MS CLR.




回答4:


I don't know about the performance but this article attempts to show how to compile the MonoDevelop tool under vs. This should give you some idea as to what the differences will be.



来源:https://stackoverflow.com/questions/1283023/performance-compile-in-vs-run-in-mono-on-windows-and-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!