How to register a global hotkey for your application in C#

How to register a global hotkey for your application in C#

Register a hotkey for your application that can be triggered even if your form is minimized and does not have focus. More »

How to download a file in C# (progressbar and download speed)

How to download a file in C# (progressbar and download speed)

Learn how to download files in C# while displaying the percentage and the download speed. More »

UDP hole punching implementation in C#

UDP hole punching implementation in C#

Learn how to implement UDP hole punching so you can make your clients life a lot easier by not forcing them to open ports on their end. More »

 

Benchmarking your code

Benchmarking your code is very important since it allows you to pinpoint bottlenecks in your application and allows you to improve the overall performance of your software as well as learning which techniques are more taxing than others.

For this example we are going to be using the Stopwatch class. This class will enable us to see how many milliseconds it required for our code to be executed so we can compare different methods or techniques.

As an example, the code below checks the performance difference of a try/catch block in a loop vs the performance when not using one. Keep in mind that try/catch blocks are not that performance heavy if they don’t actually catch something but the performance gets hit a lot in cases a lot of exceptions are being thrown.

For even better results I would advise running each test 3 to 5 times and simply calculating the average time of execution.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

One Response to Benchmarking your code

  1. Andy Bane says:

    I’m truly enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a designer to create your theme? Outstanding work!

Leave a Reply

Your email address will not be published. Required fields are marked *