Skip to content

Instantly share code, notes, and snippets.

View admir-live's full-sized avatar

Admir Mujkic admir-live

View GitHub Profile
@admir-live
admir-live / ObjectPoolBenchmarks.cs
Created May 21, 2024 18:21
Object Pool Benchmark Results
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;
@admir-live
admir-live / ClassBenchmark.cs
Created May 20, 2024 13:05
Understanding Class Performance in C#
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace ClassBenchmark
{
public class StandardClass
{
public int StandardProperty { get; set; }
public int GetStandardProperty() => StandardProperty;
@admir-live
admir-live / Number.cs
Created May 15, 2024 08:15
Number.cs
public interface INumber
{
object NumericValue { get; set; }
}
public class Number : INumber
{
public object NumericValue { get; set; }
}
@admir-live
admir-live / GenericHolderNull.cs
Created May 15, 2024 07:44
GenericHolderNull.cs
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
@admir-live
admir-live / TransactionAnalysisBenchmarkLinqAndPLinq.cs
Created May 14, 2024 05:34
This C# file benchmarks various LINQ and PLINQ methods for analyzing potentially fraudulent transactions in different dataset sizes.
using System.Security.Cryptography;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
public class Transaction
{
public decimal Amount { get; }
public TimeSpan TransactionTime { get; }
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<PersonAgeSumPerformanceBenchmark>();
[MemoryDiagnoser]
@admir-live
admir-live / BoxingPerformanceBenchmark.cs
Created May 1, 2024 01:07
This C# code defines benchmark tests to compare the performance of boxing (using a non-generic number class) versus non-boxing (using a generic number class) operations on numeric values.
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
public interface INumber
{
object NumericValue { get; set; }
}
public class Number : INumber
@admir-live
admir-live / YieldVsListPerformanceComparison.cs
Created April 25, 2024 22:37
Overview of C# Performance Benchmarking Code
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace YieldVsListPerformanceComparison
{
public class Program
{
static void Main(string[] args)
{
BenchmarkRunner.Run<PerformanceBenchmarks>();
@admir-live
admir-live / DateParsingPerformanceComparison.cs
Created March 11, 2024 23:04
DateParsingPerformanceComparison
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace ZeroAllocBenchmark
{
[MemoryDiagnoser]
public class DateParsingPerformanceComparison
{
private const string SampleDateString = "2024-03-13";
@admir-live
admir-live / CountVsAnyBenchmark.cs
Created March 5, 2024 20:21
CountVsAnyBenchmark.cs
[RankColumn]
public class CountVsAnyBenchmark
{
private List<int>? largeList;
private readonly Random random = new();
[Params(100, 10000, 1000000)]
public int NumberOfElements { get; set; }
[GlobalSetup]