Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Created March 26, 2013 09:16
Show Gist options
  • Save tugberkugurlu/5244087 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/5244087 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
Profile("i++", () =>
{
for (int i = 0; i < int.MaxValue; i++)
{
double foo = Math.Round(Math.Sqrt(3.4F) * 7823278.9F, 2);
}
});
Profile("++i", () =>
{
for (int i = 0; i < int.MaxValue; ++i)
{
double foo = Math.Round(Math.Sqrt(3.4F) * 7823278.9F, 2);
}
});
Console.ReadKey();
}
static void Profile(string description, Action func)
{
// clean up
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
// warm up
func();
var watch = Stopwatch.StartNew();
func();
watch.Stop();
Console.Write(description);
Console.WriteLine(" Time Elapsed {0} ms", watch.ElapsedMilliseconds);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment