Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimization techniques in C# [closed]

I am wondering what kind of optimization techniques people often use nowadays. I have seen people do caching all the time with dictionary and all. Is the trading space for speed the only way to go?

like image 392
Tom Avatar asked Jan 28 '09 00:01

Tom


People also ask

What are different optimization techniques?

Prominent examples include spectral clustering, matrix factorization, tensor analysis, and regularizations. These matrix-formulated optimization-centric methodologies are rapidly evolving into a popular research area for solving challenging data mining problems.

What are code Optimisation techniques?

Code Optimization Techniques. Rearranges the program code to minimize branching logic and to combine physically separate blocks of code. If variables used in a computation within a loop are not altered within the loop, the calculation can be performed outside of the loop and the results used within the loop.

How many optimization techniques are there?

There are two distinct types of optimization algorithms widely used today. (a) Deterministic Algorithms. They use specific rules for moving one solution to other. These algorithms are in use to suite some times and have been successfully applied for many engineering design problems.

What is optimization level in C?

The degree to which the compiler will optimize the code it generates is controlled by the -O flag. No optimization. In the absence of any version of the -O flag, the compiler generates straightforward code with no instruction reordering or other attempt at performance improvement. -O or -O2.


1 Answers

Really it's about your choice in algorithms. Usually there is no "silver bullet" for optimization.

For example, using a StringBuilder instead of concatenation can make your code significantly faster, but there is a tradeoff. If you aren't concatenating huge sets of strings, the memory and time it takes to initialize StringBuilder is worse than just using regular concatenation. There are a lot of examples of this throughout the framework, such as dictionary caching as you mentioned in your question.

The only general optimization you can really learn and apply to your coding throughout your day is the performance hit from boxing/unboxing (heap vs. stack). To do this you need to learn what it's about and how to avoid, or reduce the need to do it.

Microsoft's MSDN documentation has 2 articles on performance that give a lot of good general purpose techniques to use (they're really just different versions of the same article).

  • http://msdn.microsoft.com/en-us/library/ms173196.aspx
  • http://msdn.microsoft.com/en-us/library/ms173196(VS.80).aspx
like image 60
Dan Herbert Avatar answered Oct 07 '22 20:10

Dan Herbert