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
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
{
Test: pass
hash took 0.000879 seconds; 16384 unique values
Press any key to show results...
0: cc18
1: d979
2: e6db
3: f3ba
4: dd96
5: c8f7
6: f755
using System;
using System.Diagnostics;
using System.Text;
using System.Threading;
static class P {
static int remainingKeys = Crc16.RedisClusterSlotCount;
static readonly string[] keys = new string[remainingKeys];
const byte CharsStart = 33, // ignore space
CharsEnd = 126; // ignore DEL
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.Runtime.CompilerServices;
BenchmarkRunner.Run<SkipLocalsInitBenchmark>();
[SimpleJob]
public unsafe class SkipLocalsInitBenchmark
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
namespace SequenceReaderBenchmarks;
static class Program {
using System.Buffers;
int[][] matrix =
{
new [] { 1,2,3,4 },
new [] { 9,10,11,12 },
new [] { 5,6,7,8 },
};
@mgravell
mgravell / benchmark.cs
Last active January 24, 2023 16:48
ascii decode
// based on StringUtilities from dotnet/aspnetcore
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using System.Buffers;
using System.Diagnostics;
@mgravell
mgravell / bench.cs
Created January 19, 2023 14:29
bench.md
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using Grpc.Core;
using ProtoBuf.Grpc.Client;
using ProtoBuf.Grpc.Configuration;
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
BenchmarkRunner.Run<MyBenchmark>();