Skip to content

Instantly share code, notes, and snippets.

View davepcallan's full-sized avatar

Dave Callan davepcallan

View GitHub Profile
@davepcallan
davepcallan / GlobalExceptionHandler.cs
Last active March 2, 2025 13:40
ASP.NET 8 Global exception handling with IExceptionHandler example
using Microsoft.AspNetCore.Diagnostics;
namespace Samples;
public class GlobalExceptionHandler(ILogger<GlobalExceptionHandler> logger) : IExceptionHandler
{
public ValueTask<bool> TryHandleAsync(
HttpContext httpContext,
Exception exception,
CancellationToken cancellationToken)
@davepcallan
davepcallan / SBvSJBenchmarks.cs
Created February 16, 2025 15:59
StringBuilder v different String.Join overloads
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System;
using System.Collections.Generic;
using System.Text;
namespace Benchmarks
@davepcallan
davepcallan / StringConcatSimple.cs
Last active February 16, 2025 15:23
.NET 9 Simple String concatenation
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System.Runtime.CompilerServices;
using System.Text;
namespace Benchmarks
{
@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
{
@davepcallan
davepcallan / LINQBenchmarks.cs
Created February 12, 2025 12:30
.NET Framework 4.8 v .NET 9 LINQ benchmarks
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using System.Collections.Generic;
using System.Linq;
namespace Benchmarks
@davepcallan
davepcallan / AverageBlogRankingBenchmark.cs
Created February 10, 2025 21:42
Benchmarking different ways of calculating average of a column in Entity Framework
using System;
using System.Linq;
using BenchmarkDotNet.Attributes;
using Microsoft.EntityFrameworkCore;
[MemoryDiagnoser]
[ReturnValueValidator]
public class AverageBlogRanking
{
[Params(1000)]
@davepcallan
davepcallan / GettingStartedWithBenchmarkDotNet.cs
Last active February 10, 2025 18:18
Simple string concat benchmark showing how to get started with BenchmarkDotNet and how to set some basic config
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System.Text;
namespace Benchmarks;
[MemoryDiagnoser]
@davepcallan
davepcallan / GetRangeBenchmark.cs
Created February 10, 2025 14:46
Benchmark for Skip-Take, Take-Range and GetRange when working with List<T>
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System.Collections.Generic;
using System.Linq;
namespace Benchmarks
{
@davepcallan
davepcallan / IndiceAndRangeCsharp8Example.cs
Created February 3, 2025 14:37
Sample to pop straight into SharpLab to see how the indices and range syntax introduced in C# 8 gets lowered
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
var payments = new List<Payment>
{
@davepcallan
davepcallan / HybridCacheQuerying.mmd
Created January 27, 2025 04:47
HybridCache Mermaid sequence diagrams for querying HybridCache and Invalidating it in multi-instance scenario
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.