private static void Pushing(IRingBuffer ringBuffer)
        {
            Console.WriteLine($"Pushing thread: {Thread.CurrentThread.ManagedThreadId}");

            Console.WriteLine("Start pushing");
            Console.WriteLine($"Nb of elements to push: {NbOfPush}");
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            foreach (var i in Enumerable.Range(0, NbOfPush))
            {
                ringBuffer.Push(i);
            }

            stopwatch.Stop();
            Console.WriteLine($"Pushing done in {stopwatch.ElapsedMilliseconds} milliseconds");
        }
Beispiel #2
0
        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");
            }
        }
        private static void Pushing(IRingBuffer ringBuffer, int threadNumber)
        {
            Console.WriteLine($"Pushing thread {threadNumber}: {Thread.CurrentThread.ManagedThreadId}");
            Console.WriteLine($"Thread {threadNumber}: Start pushing");
            Console.WriteLine($"Thread {threadNumber}: Nb of elements to push: {NbOfPush}");
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                foreach (var i in Enumerable.Range(0, NbOfPush))
                {
                    ringBuffer.Push(i);
                }
            }
            catch (FullRingException e)
            {
                Console.WriteLine(e.Message);
            }

            stopwatch.Stop();
            Console.WriteLine($"Thread {threadNumber}: Pushing done in {stopwatch.ElapsedMilliseconds} milliseconds");
        }