Skip to content

Instantly share code, notes, and snippets.

View mgravell's full-sized avatar
🏠
Working from home

Marc Gravell mgravell

🏠
Working from home
View GitHub Profile
using System;
using System.IO;
using System.Linq;
Checkerboard.DrawCheckerboard(Console.Out, 5);
Console.WriteLine();
Checkerboard.DrawCheckerboard(Console.Out, 8);
Console.WriteLine();
static class Checkerboard
BenchmarkDotNet v0.14.0, Windows 11 (10.0.26120.1350)
AMD Ryzen 9 7900X, 1 CPU, 24 logical and 12 physical cores
.NET SDK 8.0.203
[Host] : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
DefaultJob : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
| Method | Number | Mean | Error | StdDev | Median |
|------- |------- |----------:|----------:|----------:|----------:|
| Fixed | 8 | 0.6012 ns | 0.0042 ns | 0.0037 ns | 0.6014 ns |
string src = "abc";
foreach (var chunk in src.Find(42))
{
// woohoo, this compiles!
}
static class MyHelperExtensions
{
// just exists to make the API available; "notImportant" is *all* of your
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
BenchmarkRunner.Run<PunBench>();
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.Threading.Tasks;
#if DEBUG
var obj = new AsyncMachineryBenchmarks();
// we should have done 100 things (just yields) either way
@mgravell
mgravell / Program.cs
Created January 25, 2024 14:09
float parsing
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Buffers;
using System.Text.Json;
// prove impl
var obj = new MyBench { Count = 5 };
obj.Init();
Console.WriteLine(obj.Payload);
Console.WriteLine(string.Join(',', obj.Linq()));
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Numerics;
BenchmarkRunner.Run(typeof(ConcatBenchmark).Assembly);
[MemoryDiagnoser]
public class ConcatBenchmark
{
private readonly int[] arr1 = new[] { 1, 2, 3, 4, 5, 0 },
var sb = new StringBuilder("select name from person");
if (!string.IsNullOrWhiteSpace(name))
{
sb.Append(" where name = @name");
}
var sql = sb.ToString();
foreach (var row in connection.Query<string>(sql, new { name}))
{
Console.WriteLine(row);
}
using System;
using System.Runtime.CompilerServices;
Bar b = CreateBar(42); // invoke a private .ctor
ref int x = ref GetBarX(b); // read field *ref*
Console.WriteLine(x); // deref field value
x = 17; // rewrite a private readonly field
Console.WriteLine(b.A); // 17
[UnsafeAccessor(UnsafeAccessorKind.Constructor)]
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Collections.Frozen;
using System.Collections.ObjectModel;
BenchmarkRunner.Run(typeof(DictionaryTests).Assembly, args: args);
[MemoryDiagnoser]
public class DictionaryTests
{