Skip to content

Instantly share code, notes, and snippets.

View controlflow's full-sized avatar

Alexander Shvedov controlflow

View GitHub Profile
[Pure, ContractAnnotation("null => false")]
public static bool IsValueTuple([CanBeNull] this ITypeElement typeElement)
{
var structType = typeElement as IStruct;
if (structType == null) return false;
return typeElement.ShortName == "ValueTuple"
&& typeElement.GetContainingNamespace() is INamespace ns
&& ns.ShortName == "System"
&& ns.GetContainingNamespace() is INamespace root
BenchmarkDotNet=v0.12.0, OS=Windows 10.0.17763.805 (1809/October2018Update/Redstone5), VM=VMware
Intel Core i7-7700K CPU 4.20GHz (Kaby Lake), 1 CPU, 4 logical and 4 physical cores
[Host] : .NET Framework 4.8 (4.8.4018.0), X86 LegacyJIT
DefaultJob : .NET Framework 4.8 (4.8.4018.0), X86 LegacyJIT
| Method | Count | Mean | Error | StdDev | Rank |
|--------------- |------ |------------:|----------:|----------:|-----:|
| IntArray | 1000 | 260.9 ns | 3.25 ns | 3.04 ns | 1 |
| StringArray | 1000 | 3,372.6 ns | 25.71 ns | 22.79 ns | 4 |
BenchmarkDotNet=v0.12.0, OS=Windows 10.0.17763.805 (1809/October2018Update/Redstone5), VM=VMware
Intel Core i7-7700K CPU 4.20GHz (Kaby Lake), 1 CPU, 4 logical and 4 physical cores
.NET Core SDK=2.1.507
[Host] : .NET Core 2.1.11 (CoreCLR 4.6.27617.04, CoreFX 4.6.27617.02), X64 RyuJIT
DefaultJob : .NET Core 2.1.11 (CoreCLR 4.6.27617.04, CoreFX 4.6.27617.02), X64 RyuJIT
| Method | Count | Mean | Error | StdDev | Rank |
|--------------- |------ |------------:|----------:|----------:|-----:|
| IntArray | 1000 | 407.0 ns | 5.17 ns | 4.84 ns | 1 |
@controlflow
controlflow / main.cs
Created July 14, 2021 19:19
Null check benchmarks
using System;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
// ReSharper disable RedundantToStringCall
// ReSharper disable NotAccessedField.Local
#pragma warning disable 169
BenchmarkRunner.Run<NullChecksBenchmark>();
@controlflow
controlflow / Denormals.cs
Created October 5, 2022 20:09
Denormal floating numbers playground
using System.Text;
PrintNumber(0f);
PrintNumber(-0f);
PrintNumber(1f);
PrintNumber(-1f);
PrintNumber(float.PositiveInfinity);
PrintNumber(float.NegativeInfinity);
PrintNumber(float.NaN);
PrintNumber(float.Epsilon);
using System;
using System.Threading;
using JetBrains.Annotations;
namespace JetBrains.Util.Concurrency.Threading;
/// <summary>
/// Reader-writer lock for reader-heavy scenarios.
/// </summary>
public sealed class StripedReaderWriterLock