Skip to content

Instantly share code, notes, and snippets.

View davepcallan's full-sized avatar

Dave Callan davepcallan

View GitHub Profile
@davepcallan
davepcallan / Plus-v-StringBuilder-very-simple-concat.cs
Created January 14, 2023 14:12
Concat 50K one char strings with + and StringBuilder in .NET 7
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 / dotnet9LINQCountByBenchmark.cs
Created January 29, 2024 19:43
Benchmarks for .NET 9 new LINQ CountBy() method
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
namespace Benchmarks
{
[Config(typeof(Config))]
@davepcallan
davepcallan / GetMyOrdersVSA.cs
Created January 29, 2024 15:51
GetMyOrders Vertical slice refactor example from eShopOnWeb
namespace Microsoft.eShopWeb.Features.Orders;
[Route("order/my-orders")]
public class GetMyOrdersController(CatalogContext db) : Controller
{
[HttpGet]
public async Task<IActionResult> MyOrders()
{
var userName = User.Identity.Name;
var orders = await db.Orders
@davepcallan
davepcallan / dotnet9LinqBenchmarks.cs
Last active February 8, 2024 19:00
.NET 8 v .NET 9 LINQ benchmarks
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
namespace Benchmarks
{
[Config(typeof(Config))]
@davepcallan
davepcallan / ParamsBenchmarks.cs
Created October 16, 2023 17:25
Benchmarks using the params keyword in C#
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
namespace BenchmarkDotNet.Samples
{
[Config(typeof(Config))]
[SimpleJob(RuntimeMoniker.Net80)]
@davepcallan
davepcallan / PerfSensitiveStringConcatenation.cs
Created August 14, 2023 11:57
Performance Sensitive simple string concatenation in .NET 8
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Order;
using BenchmarkDotNet.Reports;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@davepcallan
davepcallan / xUnitDataTests.cs
Created August 9, 2023 16:18
Parameterized Tests with xUnit Example
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Xunit;
public class StringFormatter
{
public string Reverse(string input)
{
@davepcallan
davepcallan / listPatternExamples.cs
Created August 3, 2023 16:33
C# 11 List Pattern Examples
namespace ListPatterns
{
internal class Program
{
static void Main(string[] args)
{
int[] numbers = { 1, 2, 3, 4};
Console.WriteLine("constant and relational patterns");
Console.WriteLine(numbers is [1, 2, 3, 4]); // True as exact match
@davepcallan
davepcallan / StringCompareDotNet8Benchmarks.cs
Created August 3, 2023 11:33
.NET 7 v .NET String.Equals OrdinalIgnoreCase benchmarks
using System.Collections.Generic;
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Environments;
namespace Benchmarks
@davepcallan
davepcallan / stringEqualsBenchmarks.cs
Created July 31, 2023 09:24
String equals benchmarks
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System;
namespace BenchmarkDotNet.Samples
{
[MemoryDiagnoser]