public void OneReaderOneWriterThreads()
        {
            var q = new SpScQueue <int>();

            var writer = new Thread(() => {
                for (var i = 1; i <= 1000; i++)
                {
                    q.Enqueue(i);
                }
            });

            var reader = new Thread(() => {
                for (var i = 1; i <= 1000; i++)
                {
                    int item;
                    while (!q.TryDequeue(out item))
                    {
                    }

                    Assert.AreEqual(i, item);
                }
            });

            writer.Start();
            reader.Start();

            reader.Join();
            writer.Join();
        }
        public void PerformanceTest()
        {
            const int n = 10000000;

            var q = new SpScQueue <int>();

            // Warm up the queue
            for (var i = 0; i < 10000; i++)
            {
                q.Enqueue(0);
            }

            for (var i = 0; i < 10000; i++)
            {
                q.Dequeue();
            }

            var writer = new Thread(() => {
                for (var i = 1; i <= n; i++)
                {
                    q.Enqueue(i);
                }
            });

            var reader = new Thread(() => {
                for (var i = 1; i <= n; i++)
                {
                    int item;
                    while (!q.TryDequeue(out item))
                    {
                    }

                    Assert.AreEqual(i, item);
                }
            });

            var start = DateTime.Now;

            writer.Start();
            reader.Start();

            reader.Join();
            writer.Join();

            var end = DateTime.Now;

            Console.WriteLine(end - start);
        }
        public void PerformanceTest()
        {
            const int n = 10000000;

            var q = new SpScQueue<int>();

            // Warm up the queue
            for (var i = 0; i < 10000; i++)
                q.Enqueue(0);

            for (var i = 0; i < 10000; i++)
                q.Dequeue();

            var writer = new Thread(() => {
                for (var i = 1; i <= n; i++)
                    q.Enqueue(i);
            });

            var reader = new Thread(() => {
                for (var i = 1; i <= n; i++) {
                    int item;
                    while (!q.TryDequeue(out item)) { }

                    Assert.AreEqual(i, item);
                }
            });

            var start = DateTime.Now;

            writer.Start();
            reader.Start();

            reader.Join();
            writer.Join();

            var end = DateTime.Now;

            Console.WriteLine(end - start);
        }
        public void OneReaderOneWriterThreads()
        {
            var q = new SpScQueue<int>();

            var writer = new Thread(() => {
                for (var i = 1; i <= 1000; i++)
                    q.Enqueue(i);
            });

            var reader = new Thread(() => {
                for (var i = 1; i <= 1000; i++) {
                    int item;
                    while (!q.TryDequeue(out item)) { }

                    Assert.AreEqual(i, item);
                }
            });

            writer.Start();
            reader.Start();

            reader.Join();
            writer.Join();
        }