Skip to content

Instantly share code, notes, and snippets.

View svick's full-sized avatar

Petr Onderka svick

View GitHub Profile
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Running;
public class Program
{
static void Main() => BenchmarkRunner.Run<Benchmark>();
}
@svick
svick / Program.cs
Created April 24, 2011 11:45
DynamicObject
using System;
using System.Dynamic;
namespace ConsoleApplication1
{
class Dynamic : DynamicObject
{
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (binder.Name == "Name")
@svick
svick / Program.cs
Last active March 3, 2020 20:04
head-tail sum perf
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Running;
public class Program
{
static bool WaitAll(Task[] tasks, int timeout, CancellationToken token)
{
var cts = CancellationTokenSource.CreateLinkedTokenSource(token);
foreach (var task in tasks)
{
task.ContinueWith(t => {
if (t.IsFaulted) cts.Cancel();
},
cts.Token,
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
public class Program
{
static void Main() => BenchmarkRunner.Run<Benchmark>();
}
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
public class Program
{
static void Main() => BenchmarkRunner.Run<Benchmark<string>>();
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using static System.Reflection.BindingFlags;
class Program
{
static void Main(string[] args)
>dotnet run -p ..\..\tools\ResultsComparer\ResultsComparer.csproj --base .\before\ --diff .\after\ --threshold 3%
summary:
better: 65, geomean: 1.629
worse: 10, geomean: 1.548
total diff: 75
Slower diff/base Base Median (ns) Diff Median (ns) Modality
using System;
using System.Reflection;
using System.Reflection.Emit;
class Program
{
static void Main()
{
var assembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("a.dll"), AssemblyBuilderAccess.Run);
var module = assembly.DefineDynamicModule("a.dll");
class DelayTaskSource
{
readonly ValueTaskSource valueTaskSource;
readonly object l = new object();
readonly List<(Action<object>, object, short)> continuations = new List<(Action<object>, object, short)>();
readonly Dictionary<short, long> timestamps = new Dictionary<short, long>();
readonly List<short> tokenCache = new List<short>();
readonly Timer timer;
long? timerTimestamp;
short nextToken;