How to quickly make my code

Please can someone point me to a good tutorial that will help me quickly and easily make my code. I am interested to know which method is faster and when to use the method instead of another ...
And how to evaluate good or bad code?
My programming language is C #.

Hello to all,
Thanks for your answers, they are very helpful. I am editing my question to be more specific, especially that optimization is unlimited.
I want to know what is the best method in every condition.
For example, using StringBuilder is better than string if I add strings to a string ... I only need these simple things.

+7
optimization c #
source share
12 answers

Keep in mind the optimization.

Although one particular function is faster than another replacement, it will not necessarily have any meaning during the execution of your application. You need to understand what parts of your code really are a potential problem and focus on optimizing these parts. Remember about O notation of your functions and how often they are called. To identify parts that need optimization, a profiler can be useful.

There are some interesting points on this question why you should not optimize until you actually need it.

+18
source share

Of course. Here is what we do:

  • Start your journey by deciding when the journey is finished. Set meaningful, customer-oriented, realistic goals. (For speed and resource consumption.)

  • Check your code carefully to see if your performance targets are right for you.

  • If you meet your performance goals, don't worry about performance. Everything is good. Worrying about errors, reliability or features.

  • If you are not meeting your performance targets, run the profiler. Use it to determine what is the worst code to break. It makes sense to fix the worst code; doing something that is already incredibly fast and easy, a little faster and easier does not solve your performance problem.

  • Rewrite the slow code to make it more efficient. (This is a hard bit.) Make sure you check it to make sure it is really better.

  • If, despite all your efforts, you cannot do it well enough, either overestimate your goals, or cancel the project and spend your time on what you can achieve success.

Keep repeating this until you send something.

+7
source share

Basically, do it first, then check where to optimize.

If you are using Visual Studio Profissional, you can use the Analyze -> Launch Performance Wizard to analyze the performance of the method. I'm not sure if other versions support this feature, however there are some commercial / free applications ... look for a profiler (see here for a list).

+5
source share

Enter REALLY fast.

+4
source share

You should look at the hidden features of C # , this post covers the best practices of developing C #

+3
source share

You can get a ton for advice on this. But keep in mind: Premature optimization is the root of all evil.

+3
source share

First verify that it is correct, then for clarity and only then performance.

As the old saying goes,

"No one cares about how quickly you can calculate the wrong answer."

(at a practical level, however, use a profiler)

+3
source share

If one method was always faster than another, they were not worried, including the slower one.

The only invariant when it comes to performance is what you need to profile. Everything follows from this.

+2
source share

If you get yourself a profiler, this will help you, some will even give you great tips.

Example: ANTS Profiler

You will usually find that reducing the number of times you create Strings is the main performance improvement you can get.

It doesn’t bother with the garbage collector manually (unless you really know what you are doing)

This link for Java design templates is too involved, do not put too much of the word Java there, you can use what they learn to develop in any language.

The fact is that if you want to know when to do what and what methods to use, and so on, design patterns are what you are talking about.

I would like someone to point this out to me earlier in my career.

+2
source share

In general tips:

  • Try to use the least number of cycles
  • Move code from loops where possible.
  • Avoid copying things (e.g. strings) into loops
  • Avoid creating objects in loops
  • The cache in which this is guaranteed (usually small objects that take a lot of time), but make sure your cache has a good recycling policy or it turns into a memory leak.
+1
source share

You can compile your program in native mode to improve execution performance.

+1
source share

One way to figure this out is with a console application where you try to run individual pieces of code against each other and synchronize them. For example here .

0
source share

All Articles