Skip to content

Instantly share code, notes, and snippets.

View sa-es-ir's full-sized avatar
🏝️

Saeed Esmaeelinejad sa-es-ir

🏝️
View GitHub Profile
@sa-es-ir
sa-es-ir / dotnet_string_encodings.cs
Last active September 30, 2024 15:10
.NET String and Encoding memory allocation
using System.Text;
var str = string.Empty;
foreach (var encoding in Encoding.GetEncodings())
{
Console.WriteLine($"string: {str} -- Encoding: {encoding.Name} -- {encoding.DisplayName} -- Bytes: {encoding.GetEncoding().GetByteCount(str)}");
}
str = "S";
foreach (var encoding in Encoding.GetEncodings())
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Reports;
using DatabaseNight.Context;
using System.Linq;
namespace DatabaseNight;
[Config(typeof(Config))]
using Avro.IO;
using Avro.Reflect;
using Avro;
using BenchmarkDotNet.Attributes;
using MessagePack;
using MongoDB.Bson;
using ProtoBuf;
using System.Text.Json;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Reports;
using EFQueryOptimization.Context;
using EFQueryOptimization.Entities;
using Microsoft.EntityFrameworkCore;
namespace EFQueryOptimization;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
namespace Benchmarks;
[SimpleJob(RuntimeMoniker.Net80, baseline: true)]
[SimpleJob(RuntimeMoniker.Net90)]
[MemoryDiagnoser(false)]
[HideColumns("RatioSD", "Median", "StdDev", "Error", "Job", "Alloc Ratio")]
public class LinqAggregateBenchmark
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Jobs;
namespace Benchmarks;
[MemoryDiagnoser(false)]
[HideColumns(Column.RatioSD, Column.AllocRatio)]
[SimpleJob(RuntimeMoniker.Net80)]
public class ListCountBenchmark
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Jobs;
using System.Text.Json;
namespace Benchmarks;
[MemoryDiagnoser(false)]
[HideColumns(Column.RatioSD, Column.AllocRatio)]
[SimpleJob(RuntimeMoniker.Net80, baseline: true)]
@sa-es-ir
sa-es-ir / ForLoopsBenchmark.cs
Last active April 23, 2024 16:35
A Comparison about C# For loops
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using System.Runtime.InteropServices;
namespace ForLoopsComparison;
[MemoryDiagnoser(false)]
[SimpleJob(RuntimeMoniker.Net60)]
[SimpleJob(RuntimeMoniker.Net80)]
[SimpleJob(RuntimeMoniker.Net90)]