Skip to content

Instantly share code, notes, and snippets.

using System.Diagnostics;
Stopwatch sw = new Stopwatch();
int count = 0;
double total = 0;
for (; ; )
{
sw.Restart();
Populate(19);
double step = sw.ElapsedMilliseconds;
Console.WriteLine("using System.Diagnostics;");
Console.WriteLine("using System.Runtime.CompilerServices;");
Console.WriteLine("using InlineIL;");
Console.WriteLine("#pragma warning disable InlineIL0100");
int count = 10000;
Console.WriteLine("Stopwatch sw = new();");
Console.WriteLine("sw.Start();");
for (int i = 0; i < count; i++)
@jkotas
jkotas / Program.cs
Created July 15, 2025 10:38
Unhandled exception
using System;
using System.Runtime.InteropServices;
class Program
{
// Define a delegate that matches the LPTHREAD_START_ROUTINE signature:
// DWORD WINAPI ThreadProc(LPVOID lpParameter);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate uint ThreadProc(IntPtr lpParameter);
@jkotas
jkotas / Program.cs
Last active May 23, 2024 05:10
naot webapi sample
using System.Text.Json.Serialization;
var builder = WebApplication.CreateSlimBuilder(args);
builder.Services.ConfigureHttpJsonOptions(options =>
{
options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
});
var app = builder.Build();
@jkotas
jkotas / ClearR2RForAPIScan.csproj
Created September 24, 2023 22:36
ClearR2RForAPIScan
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@jkotas
jkotas / Program.cs
Created August 15, 2023 01:11
RW metadata lock contention
using System.Runtime.CompilerServices;
class Test
{
static int count = 0;
static void Main()
{
for (int i = 0; i < Environment.ProcessorCount; i++)
using System.Runtime.CompilerServices;
new Thread(() => F_0_0()).Start();
new Thread(() => F_1_0()).Start();
new Thread(() => F_2_0()).Start();
new Thread(() => F_3_0()).Start();
new Thread(() => F_4_0()).Start();
new Thread(() => F_5_0()).Start();
new Thread(() => F_6_0()).Start();
new Thread(() => F_7_0()).Start();
@jkotas
jkotas / Program.cs
Created March 8, 2023 03:49
Native AOT static linking demo
using System.Runtime.InteropServices;
partial class Program
{
static void Main() => Console.WriteLine(MyMethod());
[LibraryImport("MyLibrary")]
private static partial int MyMethod();
}
using System;
class G0<T> { }
class G1<T> { }
class G2<T> { }
class G3<T> { }
class G4<T> { }
class G5<T> { }
class G6<T> { }
class G7<T> { }
class G8<T> { }
using System;
struct ArrayWrapper<T>
{
T[] _value;
public ArrayWrapper(T[] value) { _value = value; }
#if true
public static readonly ArrayWrapper<T> Empty = new ArrayWrapper<T>(Array.Empty<T>());