While this is something that a .NET developer doesn’t need
to use and care about, I have to point out that QueryPerformanceCounter
is a Windows API method that is used by some built-in .NET types behind the
scenes. This is considered an outdated approach in .NET development and you
need to use interoperability APIs to have access to this function which
provides access to a high-resolution performance counter (listing 4).
Listing 4: Using interoperability to apply
QueryPerformanceCounter
[DllImport("Kernel32.dll")]
public static extern void QueryPerformanceCounter(ref long ticks);
In the next section I apply this method to compute the time
taken to execute my benchmarks and the main reason is that I want to have a
higher precision, so using a more fundamental operating system function can
help.