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; | |
namespace SmallMethods | |
{ | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Started"); | |
var result1 = GetResultRecursively(50_000, 40_000); |
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; | |
namespace LargeMethod | |
{ | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Started"); | |
var result = GetResultRecursively(20_000); |
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 BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
namespace Benchmarking | |
{ | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ |
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
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine(Run()); | |
Console.ReadLine(); | |
} | |
public static decimal Run() | |
{ |
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
public abstract class TaxCalculator | |
{ | |
private readonly Func<TaxCalculator, decimal> _calculateDelegate; | |
protected TaxCalculator() | |
{ | |
// Generate the function only once and then call it many times. | |
_calculateDelegate = BuildExpression(this).Compile(); | |
} |
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
public class TaxCalculator1 : TaxCalculator | |
{ | |
protected override bool CanCalculateExpenses => false; | |
protected override bool CanCalculateIncomeTax => true; | |
protected override bool CanCalculateVat => false; | |
// No logic to apply. Therefore, just return 0. | |
protected override decimal CalculateExpenses(decimal input) | |
{ |
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
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine(Run()); | |
Console.ReadLine(); | |
} | |
public static decimal Run() | |
{ |
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
public abstract class TaxCalculator | |
{ | |
public decimal CalculateTaxes() | |
{ | |
decimal total = 1436; | |
if (this is ICalculateExpenses expensesCalculator) | |
{ | |
// This call would be skipped in case of TaxCalculator1 | |
total += expensesCalculator.CalculateExpenses(1436); |
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
public class TaxCalculator1 : TaxCalculator, ICalculateIncomeTax | |
{ | |
public decimal CalculateIncomeTax(decimal income) | |
{ | |
return income + 100; | |
} | |
} | |
public class TaxCalculator2 : TaxCalculator, ICalculateExpenses | |
{ |
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
public interface ICalculateExpenses | |
{ | |
decimal CalculateExpenses(decimal input); | |
} | |
public interface ICalculateIncomeTax | |
{ | |
decimal CalculateIncomeTax(decimal income); | |
} |
NewerOlder