Skip to content

Instantly share code, notes, and snippets.

@SLIB53
Created September 19, 2015 04:55
Show Gist options
  • Save SLIB53/ec19a6d2d12ae39f1a25 to your computer and use it in GitHub Desktop.
Save SLIB53/ec19a6d2d12ae39f1a25 to your computer and use it in GitHub Desktop.
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