public void Enqueue_Dequeue_IsEmpty()
        {
            var spscq = new SingleProducerSingleConsumerQueue <int>();

            Assert.True(spscq.IsEmpty);

            for (int i = 0; i < 10; i++)
            {
                spscq.Enqueue(i);
                Assert.False(spscq.IsEmpty);

                int j;
                Assert.True(spscq.TryDequeue(out j));
                Assert.Equal(i, j);
                Assert.True(spscq.IsEmpty);
            }

            const int Count = 100000;

            for (int i = 0; i < Count; i++)
            {
                spscq.Enqueue(i);
                Assert.False(spscq.IsEmpty);
            }

            for (int i = 0; i < Count; i++)
            {
                Assert.False(spscq.IsEmpty);
                int j;
                Assert.True(spscq.TryDequeue(out j));
                Assert.Equal(i, j);
            }

            Assert.True(spscq.IsEmpty);
        }
        public void Enqueue_Dequeue_IsEmpty()
        {
            var spscq = new SingleProducerSingleConsumerQueue<int>();
            Assert.True(spscq.IsEmpty);

            for (int i = 0; i < 10; i++)
            {
                spscq.Enqueue(i);
                Assert.False(spscq.IsEmpty);

                int j;
                Assert.True(spscq.TryDequeue(out j));
                Assert.Equal(i, j);
                Assert.True(spscq.IsEmpty);
            }

            const int Count = 100000;

            for (int i = 0; i < Count; i++)
            {
                spscq.Enqueue(i);
                Assert.False(spscq.IsEmpty);
            }

            for (int i = 0; i < Count; i++)
            {
                Assert.False(spscq.IsEmpty);
                int j;
                Assert.True(spscq.TryDequeue(out j));
                Assert.Equal(i, j);
            }

            Assert.True(spscq.IsEmpty);
        }
예제 #3
0
        public void PriorityChannelBenchmarkSlowWriterTryThenBlock2()
        {
            var count = 1_000_000;
            // var cts = new CancellationTokenSource();
            var pc = new SingleProducerSingleConsumerQueue <int>();

            var rt = Task.Run(() =>
            {
                using (Benchmark.Run("Read", count, true))
                {
                    var c       = 0;
                    var spinner = new SpinWait();
                    while (c < count)
                    {
                        if (pc.TryDequeue(out var i))
                        {
                            c++;
                            continue;
                        }

                        if (pc.TryDequeue(out i))
                        {
                            c++;
                            continue;
                        }
                    }
                }
            });

            var wt = Task.Run(() =>
            {
                using (Benchmark.Run("Write", count, true))
                {
                    for (var i = 0; i < count; i++)
                    {
                        var priority = false; //  i % 10 == 0;
                        pc.Enqueue(i);
                        //if (i % 100 == 0)
                        //{
                        //    if (!Thread.Yield())
                        //    {
                        //        Thread.Sleep(0);
                        //    }
                        //}
                        //else
                        //{
                        Thread.SpinWait(10);
                        //}
                    }
                }
            });

            rt.Wait();

            wt.Wait();

            Benchmark.Dump();
        }
        public void ValidateDebuggerAttributes()
        {
            var spscq = new SingleProducerSingleConsumerQueue<int>();
            DebuggerAttributes.ValidateDebuggerDisplayReferences(spscq);
            DebuggerAttributes.ValidateDebuggerTypeProxyProperties(spscq);

            for (int i = 0; i < 10; i++)
            {
                spscq.Enqueue(i);
            }
            DebuggerAttributes.ValidateDebuggerDisplayReferences(spscq);
            DebuggerAttributes.ValidateDebuggerTypeProxyProperties(spscq);
        }
        public void ValidateDebuggerAttributes()
        {
            var spscq = new SingleProducerSingleConsumerQueue <int>();

            DebuggerAttributes.ValidateDebuggerDisplayReferences(spscq);
            DebuggerAttributes.ValidateDebuggerTypeProxyProperties(spscq);

            for (int i = 0; i < 10; i++)
            {
                spscq.Enqueue(i);
            }
            DebuggerAttributes.ValidateDebuggerDisplayReferences(spscq);
            DebuggerAttributes.ValidateDebuggerTypeProxyProperties(spscq);
        }
        public void GetEnumerator()
        {
            var spscq = new SingleProducerSingleConsumerQueue<int>();

            const int Count = 100000;
            for (int i = 1; i <= Count; i++)
            {
                spscq.Enqueue(i);
            }

            int j = 1;
            foreach (int item in spscq)
            {
                Assert.Equal(j++, item);
            }
        }
        public void GetEnumerator()
        {
            var spscq = new SingleProducerSingleConsumerQueue <int>();

            const int Count = 100000;

            for (int i = 1; i <= Count; i++)
            {
                spscq.Enqueue(i);
            }

            int j = 1;

            foreach (int item in spscq)
            {
                Assert.Equal(j++, item);
            }
        }
예제 #8
0
        public void SPSCQueueBenchmark()
        {
            var count = 100_000_000;
            var spscq = new SingleProducerSingleConsumerQueue <int>();

            var wt = Task.Run(() =>
            {
                using (Benchmark.Run("Write", count, true))
                {
                    for (var i = 0; i < count; i++)
                    {
                        spscq.Enqueue(i);
                    }
                }
            });

            var rt = Task.Run(() =>
            {
                using (Benchmark.Run("Read", count, true))
                {
                    var c = 0;

                    while (c < count)
                    {
                        while (!spscq.TryDequeue(out var i))
                        {
                        }

                        c++;
                    }
                }
            });

            rt.Wait();

            wt.Wait();

            Benchmark.Dump();
        }
예제 #9
0
 // Token: 0x06006EFA RID: 28410 RVA: 0x0017DEAA File Offset: 0x0017C0AA
 public SingleProducerSingleConsumerQueue_DebugView(SingleProducerSingleConsumerQueue <T> queue)
 {
     this.m_queue = queue;
 }