Skip to content

Instantly share code, notes, and snippets.

@hypeartist
hypeartist / IsInRange.cs
Created January 11, 2024 10:36
IsInRange bench
public class Bench
{
private const int Rep = 10_000_000;
private int[] _a = new int[Rep];
[GlobalSetup]
public void Setup()
{
Random.Shared.GetItems([..Enumerable.Range(0, Rep)], _a);
}
@hypeartist
hypeartist / regexbench.cs
Last active December 25, 2023 19:54
regexbench.cs
public partial class Bench
{
private const int Rep = 10_000_000;
private readonly Regex _regex = MyRegex();
private readonly string _input = "723402139283478235u7uA874-sdjw4##7fshsjs6763820XSDFww+___43333hnd";
private int _pos = 0;
[Benchmark(Baseline = true)]
public int Test1()
@hypeartist
hypeartist / shift_rotate_avx2.cpp
Created August 30, 2023 14:51 — forked from degski/shift_rotate_avx2.cpp
lane-crossing shift and rotate instructions in AVX2
// MIT License
//
// Copyright (c) 2018 degski
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@hypeartist
hypeartist / asm.md
Last active August 9, 2023 18:48
Method calling
public class Benchmark2
{
	private Base1 _b1;
	private Base2 _b2;

	[GlobalSetup]
	public void Setup()
	{
 _b1 = new Sub1();
@hypeartist
hypeartist / ext.cs
Last active October 7, 2022 06:43
Small IJSRuntime extension method to load CSS file at runtime
public static class Utils
{
public static async ValueTask LoadCss(this IJSRuntime jsRuntime, string cssUrl)
{
await jsRuntime.InvokeVoidAsync("eval",/*lang=javascript*/$$"""
import(URL.createObjectURL(new File([`import sheet from '{{cssUrl}}' assert { type: 'css' }; document.adoptedStyleSheets = [sheet];`], `./{{Guid.NewGuid()}}.js`, { type: "text/javascript" }))).then(_=>_);
""");
}
}
@hypeartist
hypeartist / code.cs
Created July 16, 2022 19:21
Type instantiation (.ctor with parameters)
object obj;
var r = 0;
const int cnt = 1000000;
var constructorInfo = typeof(Class).GetConstructor(new[] { typeof(int) })!;
var hCtor = constructorInfo.MethodHandle;
RuntimeHelpers.PrepareMethod(RuntimeMethodHandle.FromIntPtr(hCtor.Value));
var pCtor = (delegate* managed<object, int, void>)hCtor.GetFunctionPointer();
@hypeartist
hypeartist / code.cs
Created July 16, 2022 19:19
Type instantiation (default .ctor)
object obj;
var r = 0;
const int cnt = 1000000;
var constructorInfo = typeof(Class).GetConstructor(Array.Empty<Type>())!;
var hCtorDefault = constructorInfo.MethodHandle;
RuntimeHelpers.PrepareMethod(RuntimeMethodHandle.FromIntPtr(hCtorDefault.Value));
var pCtor = (delegate*<object, void>)hCtorDefault.GetFunctionPointer();
diff --git a/src/PowerUp.Core/Decompilation/JITExtensions.cs b/src/PowerUp.Core/Decompilation/JITExtensions.cs
index 88b3397..0f18362 100644
--- a/src/PowerUp.Core/Decompilation/JITExtensions.cs
+++ b/src/PowerUp.Core/Decompilation/JITExtensions.cs
@@ -5,23 +5,18 @@ using System.Runtime.CompilerServices;
using System.Text;
using PowerUp.Core.Console;
using System.Linq;
+using System.Runtime.InteropServices;
using PowerUp.Core.Decompilation.Attributes;
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000
Intel Core i7-4702MQ CPU 2.20GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
.NET SDK=6.0.101
  [Host]   : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT
  ShortRun : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT

Job=ShortRun  Arguments=/p:DebugType=portable  IterationCount=5  
LaunchCount=1 WarmupCount=5 
@hypeartist
hypeartist / core-imaging-playground
Created February 8, 2022 13:07
core-imaging-playground
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000
Intel Core i7-4702MQ CPU 2.20GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
.NET SDK=6.0.101
[Host] : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT [AttachedDebugger]
ShortRun : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT
Job=ShortRun Arguments=/p:DebugType=portable IterationCount=5
LaunchCount=1 WarmupCount=5
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated |