Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Alexandre Mutel xoofx

🏠
Working from home
Block or report user

Report or block xoofx

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@xoofx
xoofx / BenchGCHandleReused.cs
Created Sep 21, 2019
Bench of GCHandle reused
View BenchGCHandleReused.cs
// The following benchmark shows a barely known capability of GCHandle to be reused via their .Target
// as it is avoiding to reallocate an expensive entry into the GC table handle in the CLR runtime
/*
BenchmarkDotNet=v0.10.12, OS=Windows 10.0.18362
AMD Ryzen 9 3900X 12-Core Processor, 1 CPU, 24 logical cores and 12 physical cores
.NET Core SDK=3.0.100-rc1-014190
[Host] : .NET Core 2.1.13 (Framework 4.6.28008.01), 64bit RyuJIT
DefaultJob : .NET Core 2.1.13 (Framework 4.6.28008.01), 64bit RyuJIT
@xoofx
xoofx / BenchXXH3Fast.cs
Last active Sep 14, 2019
Experiment with XXH3Fast and XXH3FastSSE
View BenchXXH3Fast.cs
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Text;
using BenchmarkDotNet.Attributes;
using StarkPlatform.NativeCompiler.Utils;
namespace StarkPlatform.NativeCompiler.Benchmarks
{
[DisassemblyDiagnoser]
public class BenchXXH3
@xoofx
xoofx / CecilTool.cs
Last active Jun 6, 2019
List usage of non public Method/Field/Type members from a specified assembly to any external assembly references
View CecilTool.cs
using System;
using System.Collections.Generic;
using System.IO;
using CecilTool;
using Mono.Cecil;
namespace CecilTool
{
/// <summary>
/// Simple tool using Mono.Cecil to dump the list of usage of internals methods/fields
@xoofx
xoofx / BenchDelegatesApp.cs
Created Feb 19, 2019
Benchmarks of calli vs delegate
View BenchDelegatesApp.cs
// | 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;
View BenchInterfaceVsIndirectCalls.cs
// Gist that shows the difference of an interface call
// Two cases in this benchmark:
// - Dictionary that should not inline
// - List that should inline
// We are also using the enumerator to show the impact on allocation as well.
/*
Method | Mean | Error | StdDev | Gen 0/1k Op | Gen 1/1k Op | Gen 2/1k Op | Allocated Memory/Op |
------------------- |----------:|----------:|----------:|------------:|------------:|------------:|--------------------:|
ProcessDictionary | 27.109 ns | 0.1258 ns | 0.1176 ns | - | - | - | - |
@xoofx
xoofx / GetGenericTypeInstances.cs
Last active Mar 23, 2018
Gets the list of the generic type instances used in an assembly
View GetGenericTypeInstances.cs
public static class AssemblyHelper
{
/// <summary>
/// Gets the list of concrete generic type instances used in an assembly.
/// See remarks
/// </summary>
/// <param name="assembly">The assembly</param>
/// <returns>The list of generic type instances</returns>
/// <remarks>
/// Note that this method fetchs only direct type instanecs but
@xoofx
xoofx / BenchVirtualVsDelegate.cs
Created Feb 22, 2018
Bench Virtual Call vs Delegate Call
View BenchVirtualVsDelegate.cs
// BenchmarkDotNet=v0.10.12, OS=Windows 10 Redstone 3 [1709, Fall Creators Update] (10.0.16299.248)
// Intel Core i7-4980HQ CPU 2.80GHz (Haswell), 1 CPU, 8 logical cores and 4 physical cores
// Frequency=2728070 Hz, Resolution=366.5595 ns, Timer=TSC
// [Host] : .NET Framework 4.6.1 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2633.0
// DefaultJob : .NET Framework 4.6.1 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2633.0
//
//
// Method | Mean | Error | StdDev |
// ------------- |----------:|----------:|----------:|
// VirtualCall | 0.9152 ns | 0.0393 ns | 0.0368 ns |
@xoofx
xoofx / asm
Last active Nov 25, 2017
Sleef_sin_u10_vs_u35
View asm
function Sleef_sinf_u10:
subq $184, %rsp
movaps %xmm15, 160(%rsp)
movaps %xmm14, 144(%rsp)
movaps %xmm13, 128(%rsp)
movaps %xmm12, 112(%rsp)
movaps %xmm11, 96(%rsp)
movaps %xmm10, 80(%rsp)
movaps %xmm9, 64(%rsp)
@xoofx
xoofx / MessSafeStack.cs
Last active Jun 6, 2017
Mess the stack by using plain safe code (cheating through ExplicitLayout/FieldOffset)
View MessSafeStack.cs
// hack for https://twitter.com/ashmind/status/871357443036467201
// Write to the stack through FieldOffset and Virtual methods (no unsafe, not using System.Runtime.InteropServices directly into a method)
// valid only for x86-32bits (need to change int Address to long in order to have it working for x64)
// The basic idea is to use FieldOffset on a struct to reinterpret an object reference
// and using this trick to take an address on the stack that doesn't involve manipulating directly IntPtr or unsafe code...
using System.Runtime.InteropServices;
class Program
View SafeNotSafe.cs
// proof of concept for breaking https://unbreakable-test.azurewebsites.net/
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
static class Program {
[MethodImpl(MethodImplOptions.NoInlining)]
public static void MethodToPatch()
{
}
You can’t perform that action at this time.