Created
May 19, 2021 03:14
-
-
Save brotatotes/a8e06b408313f041fcea60891afc820a to your computer and use it in GitHub Desktop.
ManualResetEventSlim Benchmark
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.Threading; | |
using System.Diagnostics; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
long warmupTimes = 100000000; | |
long testTimes = warmupTimes * 10; | |
// Warmup | |
CheckSet(warmupTimes); | |
CheckSet(testTimes); | |
JustSet(warmupTimes); | |
JustSet(testTimes); | |
Console.WriteLine("Hello World"); | |
} | |
private static void CheckSet(long times) | |
{ | |
Console.Write("CheckSet " + times + ": "); | |
ManualResetEventSlim e = new ManualResetEventSlim(false); | |
Stopwatch s = new Stopwatch(); | |
s.Start(); | |
for (long i = 0; i < times; i++) | |
{ | |
if (!e.IsSet) | |
{ | |
e.Set(); | |
} | |
} | |
Console.WriteLine(s.ElapsedMilliseconds / 1000.0); | |
} | |
private static void JustSet(long times) | |
{ | |
Console.Write("JustSet " + times + ": "); | |
ManualResetEventSlim e = new ManualResetEventSlim(false); | |
Stopwatch s = new Stopwatch(); | |
s.Start(); | |
for (long i = 0; i < times; i++) | |
{ | |
e.Set(); | |
} | |
Console.WriteLine(s.ElapsedMilliseconds / 1000.0); | |
} | |
} |
Author
brotatotes
commented
May 19, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment