Exemplo n.º 1
0
        public void TestBulkDequeue()
        {
            m_wait       = new ManualResetEvent(false);
            m_collection = new IsolatedQueue <int>();

            ThreadPool.QueueUserWorkItem(RunTwoBulkDequeue);
            m_wait.WaitOne();
            m_wait.Reset();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int x = 0; x < cnt; x++)
            {
                if (x % 10000 == 0)
                {
                    System.Console.WriteLine(m_collection.Count);
                    Thread.Sleep(1);
                }
                m_collection.Enqueue(x);
            }
            sw.Stop();
            System.Console.WriteLine(sw.Elapsed.TotalSeconds);
            m_wait.WaitOne();
        }
        /// <summary>
        /// Creates a new <see cref="NetworkStreamSimulator"/>
        /// </summary>
        public NetworkStreamSimulator()
        {
            m_queueA = new IsolatedQueue <byte>();
            m_queueB = new IsolatedQueue <byte>();

            ClientStream = new InternalStreams(m_queueA, m_queueB);
            ServerStream = new InternalStreams(m_queueB, m_queueA);
        }
Exemplo n.º 3
0
 public HistorianInputQueue(Func <ClientDatabaseBase <HistorianKey, HistorianValue> > getDatabase)
 {
     m_syncWrite       = new object();
     m_blocks          = new IsolatedQueue <PointData>();
     m_pointStream     = new StreamPoints(m_blocks, 1000);
     m_getDatabase     = getDatabase;
     m_worker          = new ScheduledTask(ThreadingMode.DedicatedForeground);
     m_worker.Running += WorkerDoWork;
 }
Exemplo n.º 4
0
        public void BenchmarkWrite()
        {

            string value = null;
            int x = 0;
            const int cnt = 10000;
            const int loop = 10000;

            List<string> items = new List<string>(cnt);
            for (x = 0; x < cnt; x++)
            {
                items.Add(x.ToString());
            }

            var queue = new IsolatedQueue<string>();

            Stopwatch swDequeue = new Stopwatch();
            Stopwatch swEnqueue = new Stopwatch();

            for (int repeat = 0; repeat < loop; repeat++)
            {
                swEnqueue.Start();
                foreach (var item in items)
                    queue.Enqueue(item);
                swEnqueue.Stop();

                swDequeue.Start();
                while (queue.TryDequeue(out value))
                    ;
                swDequeue.Stop();
            }


            swEnqueue.Reset();
            swDequeue.Reset();

            for (int repeat = 0; repeat < loop; repeat++)
            {
                swEnqueue.Start();
                foreach (var item in items)
                    queue.Enqueue(item);
                swEnqueue.Stop();

                swDequeue.Start();
                while (queue.TryDequeue(out value))
                    ;
                swDequeue.Stop();
            }


            System.Console.WriteLine("Enqueue " + (cnt * loop / swEnqueue.Elapsed.TotalSeconds / 1000000));
            System.Console.WriteLine("Dequeue " + (cnt * loop / swDequeue.Elapsed.TotalSeconds / 1000000));
            System.Console.WriteLine(swDequeue.Elapsed.TotalSeconds);
        }
Exemplo n.º 5
0
        public void BenchmarkBulkWrite()
        {
            //string value = null;
            //int x = 0;
            const int cnt  = 10000;
            const int loop = 10000;

            byte[] items     = new byte[cnt];
            byte[] itemsRead = new byte[cnt];

            var queue = new IsolatedQueue <byte>();

            Stopwatch swDequeue = new Stopwatch();
            Stopwatch swEnqueue = new Stopwatch();

            for (int repeat = 0; repeat < loop; repeat++)
            {
                swEnqueue.Start();
                queue.Enqueue(items, 0, items.Length);
                swEnqueue.Stop();

                swDequeue.Start();
                while (queue.Dequeue(itemsRead, 0, items.Length) > 0)
                {
                    ;
                }
                swDequeue.Stop();
            }


            swEnqueue.Reset();
            swDequeue.Reset();

            for (int repeat = 0; repeat < loop; repeat++)
            {
                swEnqueue.Start();
                queue.Enqueue(items, 0, items.Length);
                swEnqueue.Stop();

                swDequeue.Start();
                while (queue.Dequeue(itemsRead, 0, items.Length) > 0)
                {
                    ;
                }
                swDequeue.Stop();
            }


            System.Console.WriteLine("Enqueue " + (cnt * loop / swEnqueue.Elapsed.TotalSeconds / 1000000));
            System.Console.WriteLine("Dequeue " + (cnt * loop / swDequeue.Elapsed.TotalSeconds / 1000000));
            System.Console.WriteLine(swDequeue.Elapsed.TotalSeconds);
        }
Exemplo n.º 6
0
        public void TestCount()
        {
            m_collection = new IsolatedQueue <int>();
            int  value = 0;
            long count = 0;

            for (int x = 0; x < 100000; x++)
            {
                if (m_collection.Count != count)
                {
                    Assert.Fail("Count is wrong");
                }
                m_collection.Enqueue(x);
                count++;

                if (x % 10 == 0)
                {
                    m_collection.TryDequeue(out value);
                    {
                        count--;
                        if (m_collection.Count != count)
                        {
                            Assert.Fail("Count is wrong");
                        }
                    }
                }
            }

            while (m_collection.TryDequeue(out value))
            {
                count--;
                if (m_collection.Count != count)
                {
                    Assert.Fail("Count is wrong");
                }
            }
        }
 public InternalStreams(IsolatedQueue <byte> sendQueue, IsolatedQueue <byte> receiveQueue)
 {
     m_sendQueue    = sendQueue;
     m_receiveQueue = receiveQueue;
 }
 public InternalStreams(IsolatedQueue<byte> sendQueue, IsolatedQueue<byte> receiveQueue)
 {
     m_sendQueue = sendQueue;
     m_receiveQueue = receiveQueue;
 }
        /// <summary>
        /// Creates a new <see cref="NetworkStreamSimulator"/>
        /// </summary>
        public NetworkStreamSimulator()
        {
            m_queueA = new IsolatedQueue<byte>();
            m_queueB = new IsolatedQueue<byte>();

            ClientStream = new InternalStreams(m_queueA, m_queueB);
            ServerStream = new InternalStreams(m_queueB, m_queueA);
        }
Exemplo n.º 10
0
        public void BenchmarkWrite()
        {
            string    value = null;
            int       x     = 0;
            const int cnt   = 10000;
            const int loop  = 10000;

            List <string> items = new List <string>(cnt);

            for (x = 0; x < cnt; x++)
            {
                items.Add(x.ToString());
            }

            var queue = new IsolatedQueue <string>();

            Stopwatch swDequeue = new Stopwatch();
            Stopwatch swEnqueue = new Stopwatch();

            for (int repeat = 0; repeat < loop; repeat++)
            {
                swEnqueue.Start();
                foreach (var item in items)
                {
                    queue.Enqueue(item);
                }
                swEnqueue.Stop();

                swDequeue.Start();
                while (queue.TryDequeue(out value))
                {
                    ;
                }
                swDequeue.Stop();
            }


            swEnqueue.Reset();
            swDequeue.Reset();

            for (int repeat = 0; repeat < loop; repeat++)
            {
                swEnqueue.Start();
                foreach (var item in items)
                {
                    queue.Enqueue(item);
                }
                swEnqueue.Stop();

                swDequeue.Start();
                while (queue.TryDequeue(out value))
                {
                    ;
                }
                swDequeue.Stop();
            }


            System.Console.WriteLine("Enqueue " + (cnt * loop / swEnqueue.Elapsed.TotalSeconds / 1000000));
            System.Console.WriteLine("Dequeue " + (cnt * loop / swDequeue.Elapsed.TotalSeconds / 1000000));
            System.Console.WriteLine(swDequeue.Elapsed.TotalSeconds);
        }
Exemplo n.º 11
0
        public void BenchmarkBulkWrite()
        {

            //string value = null;
            //int x = 0;
            const int cnt = 10000;
            const int loop = 10000;

            byte[] items = new byte[cnt];
            byte[] itemsRead = new byte[cnt];

            var queue = new IsolatedQueue<byte>();

            Stopwatch swDequeue = new Stopwatch();
            Stopwatch swEnqueue = new Stopwatch();

            for (int repeat = 0; repeat < loop; repeat++)
            {
                swEnqueue.Start();
                queue.Enqueue(items, 0, items.Length);
                swEnqueue.Stop();

                swDequeue.Start();
                while (queue.Dequeue(itemsRead, 0, items.Length) > 0)
                    ;
                swDequeue.Stop();
            }


            swEnqueue.Reset();
            swDequeue.Reset();

            for (int repeat = 0; repeat < loop; repeat++)
            {
                swEnqueue.Start();
                queue.Enqueue(items, 0, items.Length);
                swEnqueue.Stop();

                swDequeue.Start();
                while (queue.Dequeue(itemsRead, 0, items.Length) > 0)
                    ;
                swDequeue.Stop();
            }


            System.Console.WriteLine("Enqueue " + (cnt * loop / swEnqueue.Elapsed.TotalSeconds / 1000000));
            System.Console.WriteLine("Dequeue " + (cnt * loop / swDequeue.Elapsed.TotalSeconds / 1000000));
            System.Console.WriteLine(swDequeue.Elapsed.TotalSeconds);
        }
Exemplo n.º 12
0
        public void TestBulkDequeue()
        {
            m_wait = new ManualResetEvent(false);
            m_collection = new IsolatedQueue<int>();

            ThreadPool.QueueUserWorkItem(RunTwoBulkDequeue);
            m_wait.WaitOne();
            m_wait.Reset();

            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int x = 0; x < cnt; x++)
            {
                if (x % 10000 == 0)
                {
                    System.Console.WriteLine(m_collection.Count);
                    Thread.Sleep(1);
                }
                m_collection.Enqueue(x);
            }
            sw.Stop();
            System.Console.WriteLine(sw.Elapsed.TotalSeconds);
            m_wait.WaitOne();
        }
Exemplo n.º 13
0
        public void TestCount()
        {
            m_collection = new IsolatedQueue<int>();
            int value = 0;
            long count = 0;

            for (int x = 0; x < 100000; x++)
            {
                if (m_collection.Count != count)
                    Assert.Fail("Count is wrong");
                m_collection.Enqueue(x);
                count++;

                if (x % 10 == 0)
                {
                    m_collection.TryDequeue(out value);
                    {
                        count--;
                        if (m_collection.Count != count)
                            Assert.Fail("Count is wrong");
                    }
                }
            }

            while (m_collection.TryDequeue(out value))
            {
                count--;
                if (m_collection.Count != count)
                    Assert.Fail("Count is wrong");
            }
        }
Exemplo n.º 14
0
 public StreamPoints(IsolatedQueue <PointData> measurements, int maxPointsPerStream)
 {
     m_measurements = measurements;
     m_maxPoints    = maxPointsPerStream;
 }