private static void Popping(IRingBuffer ringBuffer) { Console.WriteLine($"Popping thread: {Thread.CurrentThread.ManagedThreadId}"); Console.WriteLine("Start popping"); var stopwatch = new Stopwatch(); stopwatch.Start(); uint nbOfElementsPopped = 0; try { var spleepCount = 0; while (true) { if (spleepCount == 5) { break; } if (ringBuffer.Size() == 0) { Thread.Sleep(2); spleepCount += 1; continue; } spleepCount = 0; var r = ringBuffer.Pop(); nbOfElementsPopped += 1; } } catch (EmptyRingException e) { Console.WriteLine(e.Message); } finally { stopwatch.Stop(); Console.WriteLine($"Popping done in {stopwatch.ElapsedMilliseconds} milliseconds"); // Doesn't pop every elements due to push concurrency (NoConcurrency implementation), thread should write on the same slot // Pop 3 000 000 elements as expected with write concurrency implementation // Sometimes pop only 1 951 424 elements, correspond to 3 000 000 - 1048576 (ring size) // Issue : Read misses one complete tour of the ring Console.WriteLine($"Nb of element popped : {nbOfElementsPopped}"); } }
private static void Popping(IRingBuffer ringBuffer) { Console.WriteLine($"Popping thread: {Thread.CurrentThread.ManagedThreadId}"); Console.WriteLine("Start popping"); var stopwatch = new Stopwatch(); stopwatch.Start(); uint nbOfElementsPopped = 0; try { var spleepCount = 0; while (true) { if (spleepCount == 5) { break; } if (ringBuffer.Size() == 0) { Thread.Sleep(2); spleepCount += 1; continue; } spleepCount = 0; var r = ringBuffer.Pop(); nbOfElementsPopped += 1; } } catch (EmptyRingException e) { Console.WriteLine(e.Message); } finally { stopwatch.Stop(); Console.WriteLine($"Popping done in {stopwatch.ElapsedMilliseconds} milliseconds"); Console.WriteLine($"Nb of element popped : {nbOfElementsPopped}"); } }
public static void Sequential(IRingBuffer ringBuffer) { Console.WriteLine("Start pushing"); var stopwatch = new Stopwatch(); stopwatch.Start(); foreach (var i in Enumerable.Range(0, 1000000)) { ringBuffer.Push(i); } stopwatch.Stop(); Console.WriteLine($"Pushing done in {stopwatch.ElapsedMilliseconds} milliseconds"); Console.WriteLine($"{ringBuffer.Size()} elements inside the buffer"); Console.WriteLine("Press any key to read."); stopwatch.Reset(); stopwatch.Start(); try { while (ringBuffer.Size() > 0) { var r = ringBuffer.Pop(); } } catch (EmptyRingException e) { Console.WriteLine(e.Message); } finally { stopwatch.Stop(); Console.WriteLine($"Popping done in {stopwatch.ElapsedMilliseconds} milliseconds"); Console.WriteLine($"{ringBuffer.Size()} elements inside the buffer"); } }