Skip to content

Instantly share code, notes, and snippets.

View davepcallan's full-sized avatar

Dave Callan davepcallan

View GitHub Profile
@davepcallan
davepcallan / BloggingContext.cs
Last active February 8, 2024 19:04
Entity Framework BulkUpdate v SaveChange v Manual SQL benchmarks
using Microsoft.EntityFrameworkCore;
public class MyContext : DbContext
{
private int _batchSize;
public MyContext(int batchSize = 42)
{
_batchSize = batchSize;
}
@davepcallan
davepcallan / Benchmarks.csproj
Created February 21, 2023 08:03
OrdinalIgnoreCase .NET 7 v .NET 8 benchmarks
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.3.2064" />
@davepcallan
davepcallan / Benchmarks.csproj
Last active February 8, 2024 19:04
FrozenDictionary in .NET 8 benchmarks compared to Dictionary/ReadOnlyDictionary etc.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.3.2064" />
@davepcallan
davepcallan / gist:b8a23dee9035879e2e5a15552211c2e6
Created March 1, 2023 21:24
Apply global filters in Entity Framework
public static void ApplyGlobalFilters<TInterface>(this ModelBuilder modelBuilder,
Expression<Func<TInterface, bool>> expression)
{
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
if (entityType.ClrType.GetInterface(typeof(TInterface).Name) != null)
{
var newParam = Expression.Parameter(entityType.ClrType);
var newbody = ReplacingExpressionVisitor.
Replace(expression.Parameters.Single(), newParam, expression.Body);
@davepcallan
davepcallan / StringBuilderDotnet7-v-DotNet8.cs
Created June 17, 2023 14:14
StringBuilder Append Benchmark for .NET 7 v .NET 8
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
namespace BenchmarkDotNet.Samples
{
[Config(typeof(Config))]
@davepcallan
davepcallan / StringConcatDPGO.cs
Created June 20, 2023 16:37
.NET 8 - String concat with + and StringBuilder with PGO on v PGO off
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
namespace BenchmarkDotNet.Samples
{
@davepcallan
davepcallan / SimpleStringConcatentionDotNet8.cs
Created July 12, 2023 11:26
.NET 8 string concatenation benchmarks when concatenating only a small amount of strings
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System;
using System.Text;
namespace Benchmarks
{
@davepcallan
davepcallan / stringJoinVstringCreateSimpleConcat.cs
Created July 22, 2023 10:09
String.Create v String.Join for simple string concat
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System;
using System.Text;
namespace BenchmarkDotNet.Samples
@davepcallan
davepcallan / StringCreateSimpleConcatBenchmarks.cs
Created July 23, 2023 15:11
String interpolation v string.join v string.create for concatenation of a few strings
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System;
namespace BenchmarkDotNet.Samples
{
[MemoryDiagnoser]
@davepcallan
davepcallan / stringConcatenationDotnet8.cs
Last active February 15, 2025 22:50
.NET 8 simple string concatenation benchmarks
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System;
using System.Text;
namespace Benchmarks
{