Created
July 10, 2018 18:38
-
-
Save jkotas/8c90bc8527ab6abf85cbfe38e71380dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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