Skip to content

Instantly share code, notes, and snippets.

@jkotas
jkotas / CompareInfoResurrection.cs
Last active June 12, 2019 17:05
CompareInfoResurrection
using System;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
class Program
{
readonly static string s_shortString = new string((char)257, 1);
readonly static string s_longString = new string((char)257, 1000000);
@jkotas
jkotas / Activator.CreateInstance startup
Created June 11, 2019 01:53
Activator.CreateInstance
using System;
struct S0{ }
struct S1{ }
struct S2{ }
struct S3{ }
struct S4{ }
struct S5{ }
struct S6{ }
struct S7{ }
using System;
using System.Collections.Generic;
class MyBase : IEquatable<MyBase>
{
public string X { get; set; }
public override bool Equals(object other)
{
MyBase o = other as MyBase;
return (o != null) && Equals(o);
This file has been truncated, but you can view the full file.
using System;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Builder = System.Runtime.CompilerServices.AsyncTaskMethodBuilder<int>;
// using Awaiter = System.Runtime.CompilerServices.TaskAwaiter<string>;
// using Awaiter = System.Runtime.CompilerServices.TaskAwaiter;
@jkotas
jkotas / comtest.cs
Last active November 26, 2018 08:18
using System;
using System.Runtime.InteropServices;
[Guid("00000002-0000-0000-C000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IMalloc
{
[PreserveSig]
IntPtr Alloc(IntPtr cb);
[PreserveSig]
using System;
class Program
{
static int s;
static void m0(bool f) { if (!f) return; s*=3; s/=4; s*=5; s/=6; s*=7; s/=8; s*=9; }
static void m1(bool f) { if (!f) return; s*=3; s/=4; s*=5; s/=6; s*=7; s/=8; s*=9; }
static void m2(bool f) { if (!f) return; s*=3; s/=4; s*=5; s/=6; s*=7; s/=8; s*=9; }
static void m3(bool f) { if (!f) return; s*=3; s/=4; s*=5; s/=6; s*=7; s/=8; s*=9; }
using System;
using System.Reflection.Emit;
using System.Threading;
class Program
{
static Barrier b = new Barrier(Environment.ProcessorCount + 1);
static void Work()
{
@jkotas
jkotas / Interop
Created January 23, 2018 15:07
Interop overhead microbenchmark
using System;
using System.Security;
using System.Runtime.InteropServices;
class Test
{
[DllImport("kernel32.dll")]
[SuppressUnmanagedCodeSecurityAttribute]
extern static int GetTickCount();
@jkotas
jkotas / gist:6c92c0e432fa54a16a1a96f5e4528122
Created July 27, 2017 17:45
String::.ctor(ReadOnlySpan<char> span)
// csc /noconfig /nostdlib /r:System.Private.CoreLib.dll test.cs
using System;
using Internal.Runtime.Augments;
class My {
static void Work() {
for (;;) GC.Collect();
}
@pushd bin\Release\netcoreapp2.0\win7-x64\publish
rem !!! 2.0.0-preview2-002093-00 version below needs to be updated to the version actually used by the app !!!
copy %userprofile%\.nuget\packages\runtime.win-x64.microsoft.netcore.app\2.0.0-preview2-002093-00\tools\crossgen.exe
@FOR %%I in (*.dll) DO call :RunCrossGen %%~nI
del crossgen.exe
popd