Speeding Up C#
This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:
Firstly : Given an established C# project, what are some decent ways to speed it up beyond just plain in-code optimization?
Secondly : When writing a program from scratch in C#, what are some good ways to greatly improve performance?
Please stay away from general optimization techniques unless they are C# specific.
This has previously been asked for Python, Perl, and Java.
Off the top of my head:
object
. SuspendLayout
/ ResumeLayout
. This helps especially when using layout containers. Unfortunately, relatively few optimisations are language specific. The basics apply across languages:
When you've absolutely proved you need to micro-optimise, the profiler tends to make it obvious what to look for - things like avoiding boxing and virtual calls.
Oh, one thing I can think of which is .NET-specific: if you need to make a call frequently and are currently using reflection, convert those calls into delegates.
EDIT: The other answers suggesting using generics and StringBuilder etc are of course correct. I (probably wrongly) assumed that those optimisations were too "obvious" ;)
One simple thing is to ensure that your build configuration is set to "Release". This will enable optimizations and eliminate debugging information, making your executable smaller.
More info on MSDN if needed.
链接地址: http://www.djcxy.com/p/39594.html下一篇: 加速C#