public static void TestResetEvents(int numberOfAddition) { var stopwatch = new Stopwatch(); stopwatch.Start(); DataSharing.SyncOperationWithManualResetEvent(numberOfAddition); stopwatch.Stop(); Console.WriteLine( $"Usage of ManualResetEvent for {numberOfAddition} items took {stopwatch.ElapsedMilliseconds} ms"); stopwatch.Reset(); stopwatch.Start(); DataSharing.SyncOperationWithManualResetEventSlim(numberOfAddition); stopwatch.Stop(); Console.WriteLine( $"Usage of ManualResetEventSlim {numberOfAddition} items took {stopwatch.ElapsedMilliseconds} ms"); stopwatch.Reset(); stopwatch.Start(); DataSharing.SyncOperationWithAutoResetEvent(numberOfAddition); stopwatch.Stop(); Console.WriteLine( $"Usage of AutoResetEvent for {numberOfAddition} items took {stopwatch.ElapsedMilliseconds} ms"); }
public static void TestReaderWriterLocks(int numberOfAddition) { var stopwatch = new Stopwatch(); stopwatch.Start(); DataSharing.WriteWithReaderWriterLock(numberOfAddition); stopwatch.Stop(); Console.WriteLine( $"Usage of ReaderWriterLock for {numberOfAddition} items took {stopwatch.ElapsedMilliseconds} ms"); stopwatch.Reset(); stopwatch.Start(); DataSharing.WriteWithReaderWriterLockSlim(numberOfAddition); stopwatch.Stop(); Console.WriteLine( $"Usage of ReaderWriterLockSlim {numberOfAddition} items took {stopwatch.ElapsedMilliseconds} ms"); }
public static void TestWrittingWithSemaphores(int numberOfAddition) { var stopwatch = new Stopwatch(); stopwatch.Start(); DataSharing.WriteWithSemaphore(numberOfAddition); stopwatch.Stop(); Console.WriteLine( $"Usage of writting with semaphore for {numberOfAddition} items took {stopwatch.ElapsedMilliseconds} ms"); stopwatch.Reset(); stopwatch.Start(); DataSharing.WriteWithSemaphoreSlim(numberOfAddition); stopwatch.Stop(); Console.WriteLine( $"Usage of writting with semaphore slim {numberOfAddition} items took {stopwatch.ElapsedMilliseconds} ms"); }
public static void TestLocks(int numberOfAddition) { var stopwatch = new Stopwatch(); stopwatch.Start(); DataSharing.TestSpinLock(numberOfAddition); stopwatch.Stop(); Console.WriteLine($"Spin lock for {numberOfAddition} items took {stopwatch.ElapsedMilliseconds} ms"); stopwatch.Reset(); stopwatch.Start(); DataSharing.TestLock(numberOfAddition); stopwatch.Stop(); Console.WriteLine($"Lock for {numberOfAddition} items took {stopwatch.ElapsedMilliseconds} ms"); stopwatch.Reset(); stopwatch.Start(); DataSharing.TestInterlocked(numberOfAddition); stopwatch.Stop(); Console.WriteLine($"Interlocked for {numberOfAddition} items took {stopwatch.ElapsedMilliseconds} ms"); }