Created
September 19, 2015 04:55
-
-
Save SLIB53/ec19a6d2d12ae39f1a25 to your computer and use it in GitHub Desktop.
This file contains 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
using System; | |
using System.Diagnostics; | |
internal class Program | |
{ | |
public const int Range = 100000000; | |
public const int Input = 2; | |
private static void Main(string[] args) | |
{ | |
var watch = new Stopwatch(); | |
// Method call | |
watch.Start(); | |
for (int i = 0; i < Range; i++) | |
SomeMethod(Input); | |
watch.Stop(); | |
Console.WriteLine($"Method: {watch.ElapsedMilliseconds} ms"); | |
// Invoke anonymous function | |
watch.Start(); | |
Func<int, int> fn = (x) => { return x + x; }; | |
for (int i = 0; i < Range; i++) | |
fn.Invoke(Input); | |
watch.Stop(); | |
Console.WriteLine($"Anonymous Function: {watch.ElapsedMilliseconds} ms"); | |
// Wait.... | |
Console.Read(); | |
} | |
public static int SomeMethod(int x) | |
{ | |
return x + x; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment