Skip to content

Instantly share code, notes, and snippets.

@jkotas
Created July 10, 2018 18:38
Show Gist options
  • Save jkotas/8c90bc8527ab6abf85cbfe38e71380dd to your computer and use it in GitHub Desktop.
Save jkotas/8c90bc8527ab6abf85cbfe38e71380dd to your computer and use it in GitHub Desktop.
using System;
using System.Reflection.Emit;
using System.Threading;
class Program
{
static Barrier b = new Barrier(Environment.ProcessorCount + 1);
static void Work()
{
Action[] delegates = new Action[100000];
for (int i = 0; i < delegates.Length; i++)
{
DynamicMethod dm = new DynamicMethod("Noop", typeof(void), null);
ILGenerator iLGenerator = dm.GetILGenerator();
iLGenerator.Emit(OpCodes.Ret);
delegates[i] = ((Action)dm.CreateDelegate(typeof(Action)));
}
GC.Collect();
b.SignalAndWait();
for (int i = 0; i < delegates.Length; i++)
delegates[i]();
b.SignalAndWait();
}
static void Main(string[] args)
{
for (int i = 1; i < b.ParticipantCount; i++)
new Thread(Work).Start();
b.SignalAndWait();
int start = Environment.TickCount;
b.SignalAndWait();
int end = Environment.TickCount;
Console.WriteLine(end - start);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment