当前位置: 首页>>代码示例>>C#>>正文


C# RingBuffer.Enqueue方法代码示例

本文整理汇总了C#中RingBuffer.Enqueue方法的典型用法代码示例。如果您正苦于以下问题:C# RingBuffer.Enqueue方法的具体用法?C# RingBuffer.Enqueue怎么用?C# RingBuffer.Enqueue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RingBuffer的用法示例。


在下文中一共展示了RingBuffer.Enqueue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PerfTestThreadsWithDequeues

        public void PerfTestThreadsWithDequeues()
        {
            RingBuffer<string> ringBuffer = new RingBuffer<string>(1000);

            Stopwatch ringWatch = new Stopwatch();
            List<Task> ringTasks = new List<Task>();
            for (int t = 0; t < 10; t++)
            {
                ringTasks.Add(new Task(() =>
                {
                    for (int i = 0; i < 1000000; i++)
                    {
                        ringBuffer.Enqueue("StringOfFun");
                    }
                }));

            }
            for (int t = 0; t < 10; t++)
            {
                ringTasks.Add(new Task(() =>
                {
                    for (int i = 0; i < 1000000; i++)
                    {
                        string foo;
                        ringBuffer.TryDequeue(out foo);
                    }
                }));
            }
            ringWatch.Start();
            ringTasks.ForEach(t => t.Start());
            Task.WaitAny(ringTasks.ToArray());
            ringWatch.Stop();

            Assert.That(ringWatch.ElapsedMilliseconds, Is.LessThan(800));
        }
开发者ID:paulsuart,项目名称:rebelcmsxu5,代码行数:35,代码来源:RingBufferFixture.cs

示例2: PerfTest

        public void PerfTest()
        {
            RingBuffer<string> ringBuffer = new RingBuffer<string>(1000);
            Stopwatch ringWatch = new Stopwatch();
            ringWatch.Start();
            for (int i = 0; i < 1000000; i++)
            {
                ringBuffer.Enqueue("StringOfFun");
            }
            ringWatch.Stop();

            Assert.That(ringWatch.ElapsedMilliseconds, Is.LessThan(100));
        }
开发者ID:paulsuart,项目名称:rebelcmsxu5,代码行数:13,代码来源:RingBufferFixture.cs

示例3: PerfTestThreadsWithDequeues

        public void PerfTestThreadsWithDequeues()
        {
            RingBuffer<string> ringBuffer = new RingBuffer<string>(1000);

            Stopwatch ringWatch = new Stopwatch();
            List<Task> ringTasks = new List<Task>();
            CancellationTokenSource cancelationTokenSource = new CancellationTokenSource();
            CancellationToken cancelationToken = cancelationTokenSource.Token;
            for (int t = 0; t < 10; t++)
            {
                ringTasks.Add(new Task(() =>
                {
                    for (int i = 0; i < 1000000; i++)
                    {
                        ringBuffer.Enqueue("StringOfFun");
                    }
                }, cancelationToken));
            }
            for (int t = 0; t < 10; t++)
            {
                ringTasks.Add(new Task(() =>
                {
                    for (int i = 0; i < 1000000; i++)
                    {
                        string foo;
                        ringBuffer.TryDequeue(out foo);
                    }
                }));
            }
            ringWatch.Start();
            ringTasks.ForEach(t => t.Start());
            var allTasks = ringTasks.ToArray();
            Task.WaitAny(allTasks);
            ringWatch.Stop();
            //Cancel tasks to avoid System.AppDominUnloadException which is caused when the domain is unloaded
            //and threads created in the domain are not stopped.
            //Do this before assertions because they may throw an exception causing the thread cancellation to not happen.
            cancelationTokenSource.Cancel();
            try
            {
                Task.WaitAll(allTasks);
            }
            catch (AggregateException)
            {
                //Don't care about cancellation Exceptions.
            }
            ringTasks.ForEach(t => t.Dispose());
            Assert.That(ringWatch.ElapsedMilliseconds, Is.LessThan(800));
        }
开发者ID:JohnDRoach,项目名称:Log4Net.Async,代码行数:49,代码来源:RingBufferTest.cs

示例4: WhenRingSizeLimitIsHit_ItemsAreDequeued

        public void WhenRingSizeLimitIsHit_ItemsAreDequeued()
        {
            // Arrange
            const int limit = 2;
            object object1 = "one";
            object object2 = "two";
            object object3 = "three";
            RingBuffer<object> queue = new RingBuffer<object>(limit);

            // Act
            queue.Enqueue(object1);
            queue.Enqueue(object2);
            queue.Enqueue(object3);

            // Assert
            object value;
            queue.TryDequeue(out value);
            Assert.That(value, Is.EqualTo(object2));
            queue.TryDequeue(out value);
            Assert.That(value, Is.EqualTo(object3));
            queue.TryDequeue(out value);
            Assert.That(value, Is.Null);
        }
开发者ID:paulsuart,项目名称:rebelcmsxu5,代码行数:23,代码来源:RingBufferFixture.cs


注:本文中的RingBuffer.Enqueue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。