A couple of years ago I was living and working in Belgium. I joined a small team of SharePoint specialists to build a custom application for a financial institution in Brussels. We were writing a lot of hand-coded C#.
I worked with a colleague who was fresh out of college with a computer science education under his belt. But I noticed something very interesting: even though he could write perfectly functional C# code, nobody had ever taught him how to write fast and efficient code.
Here's an example. Take a look at these two code snippets:
Which code snippet do you think is the fastest?
Now, to be fair, my colleague had heard of a StringBuilder. But nobody had ever explained to him why it exists, so he didn’t realize when he should use it.
Seasoned C# developers will know that the code on the left is extremely inefficient for large loops because in C# strings are optimized for comparing, not for modifying. The heap will be littered with out-of-scope copies of the string. We're supposed to use the StringBuilder class here, because it is optimized for modifying.
But let’s face it: the NET Framework is huge. For any given problem there are many competing solutions, and it is not always clear which solution is the best choice.
I created this course specifically for people like my colleague: developers who already have a working knowledge of C# programming, but who want to learn how to write fast and efficient code, and gain more understanding of what is going on under the hood of the .NET Framework.
“An eye-opening look under the hood of your code.”
- Mark Miller, course student
In the course, I cover many common performance bottlenecks. I introduce each problem with a small test program to measure the baseline performance. Then I’ll demonstrate a couple of possible solution, and benchmark how each solution measures up.
I also added a section on Common Intermediate Code (CIL), the ‘machine’ language that the C# compiler compiles to. The CIL language is very easy to read and understand, I cover all the basics in a short 15-minute lecture.
Being able to read CIL code is an extremely useful skill that will help you analyze the output of the C# compiler, and help you avoid many performance pitfalls of the NET Framework.