BufferPoolTest.Program.TestBufferPool C# (CSharp) Method

TestBufferPool() static private method

static private TestBufferPool ( ) : void
return void
        static void TestBufferPool()
        {
            bool console = Interlocked.Increment(ref count) == 1;
            Thread.Sleep(100);

            Item[] dequeued = new Item[actions];

            int start = Environment.TickCount;
            int actionPower = 24;
            Int64 actionPowered = 1 << actionPower;
            while (run)
            {
                for (int i = 0; i < dequeued.Length; i++)
                {
                    if (testPool)
                        dequeued[i] = pool.Get();
                    else
                    {
                        int index = queue.Dequeue();
                        dequeued[i] = array[index].Value;
                        array[index].Value = null;
                        stack.Push(index);
                    }
                }

                for (int i = 0; i < dequeued.Length; i++)
                {
                    if (items[dequeued[i].TestIndex])
                        Console.WriteLine(@"Error");
                    else
                        items[dequeued[i].TestIndex] = true;
                }

                for (int i = 0; i < dequeued.Length; i++)
                    items[dequeued[i].TestIndex] = false;

                for (int i = 0; i < dequeued.Length; i++)
                {
                    if (testPool)
                        pool.Put(dequeued[i]);
                    else
                    {
                        int index = stack.Pop();
                        array[index].Value = dequeued[i];
                        queue.Enqueue(index);
                    }

                    Interlocked.Increment(ref actionCount);
                }

                if (console)
                {
                    if (actionPowered < actionCount)
                    {
                        int ms = Environment.TickCount - start;
                        double speed = (double)Thread.VolatileRead(ref actionCount) / (double)ms;
                        Console.WriteLine("Reach 2 ^ {0}: {1} ms, {2:0.00} per/ms", actionPower, ms, speed);
                        actionPower++;
                        actionPowered <<= 1;
                    }
                }
            }

            Interlocked.Decrement(ref count);
        }