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 BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Configs; | |
using BenchmarkDotNet.Running; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.ObjectPool; | |
using System; | |
using System.Linq; | |
using System.Security.Cryptography; | |
using System.Threading.Tasks; |
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 BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
namespace ClassBenchmark | |
{ | |
public class StandardClass | |
{ | |
public int StandardProperty { get; set; } | |
public int GetStandardProperty() => StandardProperty; |
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 INumber | |
{ | |
object NumericValue { get; set; } | |
} | |
public class Number : INumber | |
{ | |
public object NumericValue { get; set; } | |
} |
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
var intHolder = new Number<int?>(null); // T is int?, which can be null | |
var stringHolder = new Number<string>("Hello"); // T is string | |
var objectHolder = new Number<object>(new object()); // T is object | |
var nullableHolder = new Number<int?>(5); // T is int?, with a value | |
Console.WriteLine(intHolder.Value); // Output: null | |
Console.WriteLine(stringHolder.Value); // Output: Hello | |
Console.WriteLine(objectHolder.Value); // Output: System.Object | |
Console.WriteLine(nullableHolder.Value); // Output: 5 |
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.Security.Cryptography; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Reports; | |
using BenchmarkDotNet.Running; | |
public class Transaction | |
{ | |
public decimal Amount { get; } | |
public TimeSpan TransactionTime { get; } |
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.Collections.Generic; | |
using System.Runtime.InteropServices; | |
using System.Threading.Tasks; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
BenchmarkRunner.Run<PersonAgeSumPerformanceBenchmark>(); | |
[MemoryDiagnoser] |
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; | |
public interface INumber | |
{ | |
object NumericValue { get; set; } | |
} | |
public class Number : INumber |
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 BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
namespace YieldVsListPerformanceComparison | |
{ | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
BenchmarkRunner.Run<PerformanceBenchmarks>(); |
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 BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
namespace ZeroAllocBenchmark | |
{ | |
[MemoryDiagnoser] | |
public class DateParsingPerformanceComparison | |
{ | |
private const string SampleDateString = "2024-03-13"; |
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
[RankColumn] | |
public class CountVsAnyBenchmark | |
{ | |
private List<int>? largeList; | |
private readonly Random random = new(); | |
[Params(100, 10000, 1000000)] | |
public int NumberOfElements { get; set; } | |
[GlobalSetup] |
NewerOlder