예제 #1
0
        public void LastDequeueTest()
        {
            var q = new ManagedQueue <GenericClass>();

            Console.WriteLine("---------Queue Created---------");
            Thread.Sleep(5000);
            Console.WriteLine(q.WaitingTime);
            q.Enqueue(new GenericClass());
            Thread.Sleep(5000);
            q.Enqueue(new GenericClass());
            Thread.Sleep(10000);
            Console.WriteLine(q.WaitingTime); //output should be ~15 seconds
            q.TryDequeue(out _);
            Thread.Sleep(5000);
            Console.WriteLine(q.WaitingTime); //output should be ~5 seconds
            Thread.Sleep(5000);
            q.TryDequeue(out _);
            Thread.Sleep(5000);
            Console.WriteLine(q.WaitingTime);//output should be ~5 seconds
        }
예제 #2
0
        public void ParallelEnqueuesTest()
        {
            Console.WriteLine(_queue.History.Count);
            List <GenericClass> list = _queue.ToList();
            var q = new ConcurrentQueue <GenericClass>();

            _queue.Clear();
            list.ForEach(i => _queue.Enqueue(i));
            Console.WriteLine(_queue.History.Count);
            list.ForEach(i => q.Enqueue(i));
            _queue.Clear();
            q.Clear();
            list.AsParallel().ForAll(i => _queue.Enqueue(i));
            Console.WriteLine(_queue.History.Count);
            list.AsParallel().ForAll(i => q.Enqueue(i));
            list.AsParallel().ForAll(i => _queue.TryDequeue(out _));
            Console.WriteLine(_queue.History.Count);
            list.AsParallel().ForAll(i => q.TryDequeue(out _));
        }
예제 #3
0
        public void GrowthRateTest()
        {
            var q = new ManagedQueue <GenericClass>();

            for (int i = 0; i < 375600; i++)
            {
                switch (new Random().Next(1, 3))
                {
                case 1:
                    q.Enqueue(new GenericClass());
                    break;

                case 2:
                    q.TryDequeue(out _);
                    break;
                }
                Console.WriteLine(q.GrowthRate);
                //Thread.Sleep(500);
            }
        }