Esempio n. 1
0
        public void AFillTest()
        {
            var buffer = new MpmcRingBuffer <ClassTest>(0x10);
            var value  = new ClassTest();

            for (long i = 0; i < 0x10; i++)
            {
                Assert.IsTrue(buffer.Offer(value));
            }
            Assert.IsFalse(buffer.Offer(value));
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var buffer       = new MpmcRingBuffer <MyTestClass>(0x4000000);
            var goThrough    = 100_000_000;
            var threadCount  = 2;
            var writeThreads = new Thread[threadCount];
            var readThreads  = new Thread[threadCount];
            var value        = new MyTestClass();
            var stopWatch    = new Stopwatch();

            for (var i = 0; i < threadCount; i++)
            {
                writeThreads[i] = new Thread((obj) =>
                {
                    for (var j = 0; j < goThrough; j++)
                    {
                        buffer.Offer(value);
                    }
                });
                readThreads[i] = new Thread((obj) =>
                {
                    for (var j = 0; j < goThrough; j++)
                    {
                        buffer.TryPoll(out MyTestClass ignore);
                    }
                });
            }

            for (var i = 0; i < threadCount; i++)
            {
                writeThreads[i].Start();
                readThreads[i].Start();
            }
            stopWatch.Start();
            for (var i = 0; i < threadCount; i++)
            {
                writeThreads[i].Join();
                readThreads[i].Join();
            }

            var time = stopWatch.ElapsedMilliseconds;

            File.WriteAllText(@"D:\Ran.txt", $"Ran in {time}");
        }
Esempio n. 3
0
        public void DrainTest()
        {
            var buffer = new MpmcRingBuffer <ClassTest>(0x100);

            var goThrough    = 10000;
            var threadCount  = 5;
            var writeThreads = new Thread[threadCount];
            var readThreads  = new Thread[threadCount];
            var value        = new ClassTest();

            for (var i = 0; i < threadCount; i++)
            {
                writeThreads[i] = new Thread((obj) =>
                {
                    for (var j = 0; j < goThrough; j++)
                    {
                        buffer.Offer(value);
                    }
                });
                readThreads[i] = new Thread((obj) =>
                {
                    for (var j = 0; j < goThrough; j++)
                    {
                        buffer.Drain((me) =>
                        {
                        }, 100);
                    }
                });
            }

            for (var i = 0; i < threadCount; i++)
            {
                writeThreads[i].Start();
                readThreads[i].Start();
            }

            for (var i = 0; i < threadCount; i++)
            {
                writeThreads[i].Join();
                readThreads[i].Join();
            }
        }