Created
September 16, 2015 14:10
-
-
Save danielwertheim/27f2b361ae42bc0f9dcb to your computer and use it in GitHub Desktop.
ReleaseDebugInlining
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; | |
using System.Runtime.CompilerServices; | |
namespace DebugVsRelease | |
{ | |
class Constants | |
{ | |
public const int Itterations = 1000000; | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var fiddler = new Fiddler(); | |
var sw = new Stopwatch(); | |
try | |
{ | |
long sum = 0; | |
for (var i = 1; i <= Constants.Itterations; i++) | |
{ | |
sw.Start(); | |
var r = fiddler.FiddleWithThis(0, i); | |
sw.Stop(); | |
sum += r; | |
} | |
Console.WriteLine(sum); | |
} | |
catch (Exception ex) | |
{ | |
sw.Stop(); | |
Console.WriteLine("EC " + fiddler.ErrCount); | |
Console.WriteLine(ex.ToString()); | |
} | |
Console.WriteLine(sw.Elapsed.TotalMilliseconds); | |
Console.ReadKey(); | |
} | |
} | |
public class Fiddler | |
{ | |
public int ErrCount = 0; | |
public int FiddleWithThis(int a, int b) | |
{ | |
return TestA(a, b); | |
} | |
//[MethodImpl(MethodImplOptions.NoInlining)] | |
private int TestA(int x, int y) | |
{ | |
return TestB(x, y); | |
//try | |
//{ | |
// return TestB(x, y); | |
//} | |
//catch (Exception) | |
//{ | |
// ErrCount++; | |
// throw; | |
//} | |
} | |
//[MethodImpl(MethodImplOptions.NoInlining)] | |
private int TestB(int x, int y) | |
{ | |
return TestC(x, y); | |
//try | |
//{ | |
// return TestC(x, y); | |
//} | |
//catch (Exception) | |
//{ | |
// ErrCount++; | |
// throw; | |
//} | |
} | |
private int TestC(int x, int y) | |
{ | |
if (y == Constants.Itterations) | |
throw new Exception("Failed in TestC."); | |
return x + y; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment