Created
December 22, 2015 00:14
-
-
Save kendallmiller/3bb762cd4d609d979aed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Delegate_Perf_Test | |
| { | |
| [TestFixture] | |
| public class Delegate_Performance_Comparision | |
| { | |
| [Test] | |
| public void MeasureDelegate() | |
| { | |
| int n = 50000000; | |
| Action<int> d = MethodNoInlining; | |
| var stopwatch = Stopwatch.StartNew(); | |
| for (int i = 0; i < n; ++i) | |
| { | |
| d(i); | |
| } | |
| stopwatch.Stop(); | |
| Console.WriteLine("Delegate Call: " + stopwatch.Elapsed); | |
| stopwatch = Stopwatch.StartNew(); | |
| for (int i = 0; i < n; ++i) | |
| { | |
| MethodNoInlining(i); | |
| } | |
| stopwatch.Stop(); | |
| Console.WriteLine("Direct Call Not Inlined: " + stopwatch.Elapsed); | |
| stopwatch = Stopwatch.StartNew(); | |
| for (int i = 0; i < n; ++i) | |
| { | |
| MethodWithInlining(i); | |
| } | |
| stopwatch.Stop(); | |
| Console.WriteLine("Direct Call Inlined: " + stopwatch.Elapsed); | |
| } | |
| [MethodImpl(MethodImplOptions.NoInlining)] | |
| private void MethodNoInlining(int x) | |
| { | |
| x = x + 1; | |
| } | |
| private void MethodWithInlining(int x) | |
| { | |
| x = x + 1; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment