Experiment with this gist in Gistlyn.
Let's start with the big guns: Discriminated Union in C#.
| <Project Sdk="Microsoft.NET.Sdk"> | |
| <PropertyGroup> | |
| <OutputType>Exe</OutputType> | |
| <TargetFramework>net5.0</TargetFramework> | |
| <LangVersion>preview</LangVersion> | |
| </PropertyGroup> | |
| <ItemGroup> | |
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0-preview.3.20215.2" /> | |
| </ItemGroup> | |
| <ItemGroup> |
| /* | |
| sources: | |
| - http://www.adammil.net/blog/v111_Creating_High-Performance_Locks_and_Lock-free_Code_for_NET_.html | |
| - http://badamczewski.blogspot.com/2012/08/lock-free-and-spinwait-msdn-example.html | |
| A better spin lock: | |
| The result is a spin lock that's quite fast — about twice as fast as locking with a Monitor (or the C# lock statement). | |
| (It can be further sped up slightly by breaking the Enter method into two methods: Enter, |
| <Project Sdk="Microsoft.NET.Sdk"> | |
| <PropertyGroup> | |
| <OutputType>Exe</OutputType> | |
| <TargetFramework>net472</TargetFramework> | |
| </PropertyGroup> | |
| <PropertyGroup> | |
| <GeneratedText><![CDATA[ | |
| using System%3B |
| using System; | |
| using ImTools; | |
| public class Program | |
| { | |
| public static void Main() | |
| { | |
| var map = ImHashMap<string, string>.Empty; | |
| var map1 = map.AddOrUpdate("a", "42"); |
| private DictionarySlim<TypeVal, string> _dict; | |
| public DictionarySlim<TypeVal, string> DictSlim() | |
| { | |
| var dict = new DictionarySlim<TypeVal, string>(); | |
| foreach (var key in _keys.Take(Count)) | |
| dict.GetOrAddValueRef(key) = "a"; | |
| dict.GetOrAddValueRef(typeof(ImHashMapBenchmarks)) = "!"; |
| module EnvDemo | |
| open System | |
| open System.IO | |
| [<Struct>] | |
| type Nothing = | |
| private | |
| | Nothing |
| using System; | |
| class Program | |
| { | |
| // M wants to get an instance via Func | |
| static void M(Func<string> factory) | |
| { | |
| Console.WriteLine(factory()); | |
| } |
| // | Method | Mean | Error | StdDev | | |
| // |------------- |----------:|----------:|----------:| | |
| // | Calli | 0.6718 ns | 0.0013 ns | 0.0012 ns | | |
| // | Delegate | 1.1366 ns | 0.0099 ns | 0.0088 ns | | |
| // | FastDelegate | 1.6239 ns | 0.0103 ns | 0.0097 ns | | |
| // MyClassLib.cs is compiled in another project (havent tested if compiling with Fody is working with BenchmarkDotnet in the same project) | |
| // This file is referencing BenchDelegates.MyClassLib | |
| using System; |
| /* | |
| https://dba.stackexchange.com/questions/96534/postgres-check-disk-space-taken-by-materialized-view?newreg=6b1d58604fce4a1fbe3033ddbb52d7ca | |
| relkind: | |
| r = ordinary table, | |
| i = index, | |
| S = sequence, | |
| v = view, | |
| m = materialized view, | |
| c = composite type, |
Experiment with this gist in Gistlyn.
Let's start with the big guns: Discriminated Union in C#.