
Named parameters are an alternate parameter syntax. They sometimes result in easier to read and clearer code. They are checked for correctness by the compiler. By specifying the formal parameter name, you can reorder the actual arguments you pass.
This C# performance article tests named parameters. It provides benchmarks.

To start, this example program introduces two methods: the Main entry point, and the Test method. In the Main method, the Test method is called in four different ways. We use the syntax "name:" and then a string literal to specify the value of the name parameter; the syntax "size:" and then an integer signifies the size parameter. You can reorder these named parameters in any way you want. Also, you can specify names on only some parameters.
Program that uses named parameters [C# 4.0]
using System;
class Program
{
static void Main()
{
// Call the Test method several times in different ways.
Test(name: "Perl", size: 5);
Test(name: "Dot", size: -1);
Test(6, "Net");
Test(7, name: "Google");
}
static void Test(int size, string name)
{
Console.WriteLine("Size = {0}, Name = {1}", size, name);
}
}
Output
Size = 5, Name = Perl
Size = -1, Name = Dot
Size = 6, Name = Net
Size = 7, Name = GoogleIntermediate language. In the C# language, all programs are compiled into an intermediate representation commonly referred to as MSIL, which is essentially a high-level abstract assembly language. For the named parameters feature, the compiler uses temporary local variables and then reorders those locals in the argument slots. In essence, the compiler simply infers the regular order from the new syntax.
Intermediate Language
The intermediate language representation of named parameters introduces extra local variables and assignments before passing the arguments. To demonstrate the performance effect of named parameters, this program introduces two methods, Method1 and Method2: in these methods, a third method Method3 is called with named parameter syntax and classic parameter syntax.
Note: Please disregard the logic of Method3 as it is there mainly to ensure the method is not inlined.
Program that tests named parameter performance [C# 4.0]
using System;
using System.Diagnostics;
class Program
{
const int _max = 100000000;
static void Main()
{
Method1();
Method2();
var s1 = Stopwatch.StartNew();
for (int i = 0; i < _max; i++)
{
Method1();
}
s1.Stop();
var s2 = Stopwatch.StartNew();
for (int i = 0; i < _max; i++)
{
Method2();
}
s2.Stop();
Console.WriteLine(((double)(s1.Elapsed.TotalMilliseconds * 1000 * 1000) /
_max).ToString("0.00 ns"));
Console.WriteLine(((double)(s2.Elapsed.TotalMilliseconds * 1000 * 1000) /
_max).ToString("0.00 ns"));
Console.Read();
}
static void Method1()
{
Method3(flag: true, size: 1, name: "Perl");
}
static void Method2()
{
Method3(1, "Perl", true);
}
static void Method3(int size, string name, bool flag)
{
if (!flag && size != -1 && name != null)
{
throw new Exception();
}
}
}
Output
2.88 ns [named parameters]
0.33 ns
Results. The results of this program for the .NET Framework version 4.0 are interesting: they show that named parameters have a substantial performance drawback. The likely reason for this is that the named parameters are transformed into local variables, and as Method1 is called, memory on the virtualized stack must be allocated each time. Therefore, more stack memory is used and performance suffers.

Opinion. It is unfortunate that the C# compiler cannot adequately optimize named parameter calls into the performance equivalent of regular method calls. If every method call on your computer was 2.5 nanoseconds slower, your computer would be (even more) miserable to use. Therefore, named parameters should be avoided in most C# program contexts where they do not dramatically increase readability.

The named parameters feature in new versions of the C# programming language introduces syntactic sugar for method calls. Perhaps most intriguing, this feature embeds more contextual information into method calls, making some source text possibly clearer to read and understand.
Syntactic Sugar Method Tips