Tag Archives: performance

Remove unnecessary using directives in C#

The top of a C# code file usually includes series of using directives to tell Visual Studio which namespaces are used by the code. When you first create a project, the code files include lots of using directives that might … Continue reading

Posted in coding, performance | Tagged , , , , , , , , , | Leave a comment

Efficiently see if a string is blank in C#

This example uses three strings to compare different methods for determining whether a string is blank. One of the methods, the string class’s IsNullOrWhiteSpace method, only works in .NET Framework 4.5 or later, so this example targets that version of … Continue reading

Posted in performance, strings | Tagged , , , , , , , , , , , , , , | 5 Comments

Compare performance looping over DateTime and integer variables in C#

The example Find Friday the Thirteenths in C# doesn’t really worry about performance. It uses integers to loop over the dates within a range. For every year between the start and end dates, the code considers the 13th of each … Continue reading

Posted in performance, syntax | Tagged , , , , , , , , , , , , , , | Leave a comment

Find Friday the Thirteenths in C#

The following code shows how this example lists the Friday the Thirteenths between selected start and end dates. // List Friday the 13ths between the start and end dates. private void btnGo_Click(object sender, EventArgs e) { lstResults.Items.Clear(); // Get the … Continue reading

Posted in performance, syntax | Tagged , , , , , , , , , , , | 1 Comment

Compare the performance of simple arithmetic operations in C#

I saw a post the other day that said division was the slowest arithmetic operation so I wrote this example to see exactly how the performance of multiplication, division, addition, and subtraction differ with floating point numbers. When you click … Continue reading

Posted in mathematics, performance | Tagged , , , , , , , , , , , | 1 Comment

Compare the performance of the int, long, and byte data types in C#

The example Compare the performance of the float, double, and decimal data types in C# compares the performance of the float, double, and decimal data types. This example performs a similar test for the int, long, and byte data types. … Continue reading

Posted in performance, variables | Tagged , , , , , , , , , , , | Leave a comment

Compare the performance of the float, double, and decimal data types in C#

A computer’s math coprocessor typically gives the best performance with a particular data type. To see which works best on my system and to learn how big the difference is, I wrote this program to compare the performance of calculations … Continue reading

Posted in performance, variables | Tagged , , , , , , , , , , | 6 Comments

Compare sorting algorithms in C#, article 5 of 5

Countingsort The discussion of Quicksort in my previous post mentions that the fastest possible sorting algorithms that use comparisons take on the order of N * log(N) steps. Countingsort does not use comparisons so it is not bound by that … Continue reading

Posted in algorithms, performance | Tagged , , , , , , , , , , , , , , | Leave a comment

Compare sorting algorithms in C#, part 3 of 5

Selectionsort Selectionsort is a very simple algorithm. First you search the list for the smallest item. Then you swap that item with the item at the top of the list. Next you find the second smallest item and swap it … Continue reading

Posted in algorithms, performance | Tagged , , , , , , , , , , , , , , | Leave a comment

Compare sorting algorithms in C#, part 2 of 5

Bubblesort Bubblesort is a specialized algorithm designed for sorting items that are already mostly in sorted order. If only one or two items in your list are out of order, Bubblesort is very fast. If the items in your list … Continue reading

Posted in algorithms, performance | Tagged , , , , , , , , , , , , , , | Leave a comment