O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Cost of Optimization

Imagine you were to write a query as follows:

var groups = new Dictionary<string, List<Process>>();foreach (var proc in Process.GetProcesses()){    if (proc.ProcessName.StartsWith("d"))    {        List<Process> bucket;        if (groups.TryGetValue(proc.ProcessName, out bucket))            bucket.Add(proc);        else            groups[proc.ProcessName] = new List<Process>() { proc };    }}

It’s most likely not immediately apparent to you this is carrying out a filtering operation as well as a grouping operation, let alone that the runtime would be able to see our intent from the rather complex preceding code. Also because you’ve prescribed the recipe to execute your algorithm very precisely, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required