Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speeding Up C#

Tags:

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.

like image 406
akdom Avatar asked Oct 08 '08 14:10

akdom


People also ask

Which is faster C or C+?

Performance: C++ is widely used when higher level languages are not efficient. C++ code is much faster than C# code, which makes it a better solution for applications where performance is important.

Which for loop will run faster in C?

Faster for() loops If you don't care about the order of the loop counter, you can do this instead: for( i=10; i--; ) { ... } Using this code, i loops through the values 9,8,7,6,5,4,3,2,1,0, and the loop should be faster.

How do you speed up a loop in C++?

For the access to a an element you will have to do the index calculation yourself. But as one of the indices (j) is constant over the loop, you can compute the start element's index before the loop and inside just increment the index 1. That might get you some significant improvement.


1 Answers

Off the top of my head:

  • Replace non-generic variants of container classes by their generic counterparts
  • Cut down on boxing/unboxing. Specifically, use generics where possible and generally avoid passing value types as object.
  • For dialogs using many dynamic controls: suspend drawing until after inserting all controls by using SuspendLayout/ResumeLayout. This helps especially when using layout containers.
like image 169
Konrad Rudolph Avatar answered Oct 27 '22 11:10

Konrad Rudolph