Exemplo n.º 1
0
        public void ParsingBlockingVsNonBlocking5()
        {
            this.EnsureNIOData();

            Stopwatch timer = new Stopwatch();
            TimeSpan  blockingTime = new TimeSpan(), nonBlockingTime = new TimeSpan();

            for (int i = 0; i < 25; i++)
            {
                Console.WriteLine("Run #" + (i + 1));
                timer.Reset();

                //Test Blocking
                BlockingTextReader blocking = ParsingTextReader.CreateBlocking(new JitterReader(new StreamReader("resources\\nio.ttl"), 50));
                timer.Start();
                int totalBlocking = 0;
                int read;
                while (!blocking.EndOfStream)
                {
                    read = blocking.Read();
                    if (read >= 0)
                    {
                        totalBlocking++;
                    }
                }
                timer.Stop();
                blocking.Close();
                blockingTime = blockingTime.Add(timer.Elapsed);

                Console.WriteLine("Blocking IO took " + timer.Elapsed + " and read " + totalBlocking + " characters");

                //Reset
                timer.Reset();
                int totalNonBlocking = 0;

                NonBlockingTextReader nonBlocking = ParsingTextReader.CreateNonBlocking(new JitterReader(new StreamReader("resources\\nio.ttl"), 50));
                timer.Start();
                while (!nonBlocking.EndOfStream)
                {
                    read = nonBlocking.Read();
                    if (read >= 0)
                    {
                        totalNonBlocking++;
                    }
                }
                timer.Stop();
                nonBlocking.Close();
                nonBlockingTime = nonBlockingTime.Add(timer.Elapsed);

                Console.WriteLine("Non-Blocking IO took " + timer.Elapsed + " and read " + totalNonBlocking + " characters");

                Assert.AreEqual(totalBlocking, totalNonBlocking);
            }

            Console.WriteLine();
            Console.WriteLine("Blocking Total Time = " + blockingTime);
            Console.WriteLine("Non-Blocking Total Time = " + nonBlockingTime);
        }
Exemplo n.º 2
0
        public void ParsingBlockingVsNonBlocking3()
        {
            this.EnsureNIOData();

            Stopwatch timer = new Stopwatch();
            TimeSpan  blockingTime = new TimeSpan(), nonBlockingTime = new TimeSpan();

            int maxSize = 1024 * 32;

            for (int size = 1024; size < maxSize; size += 1024)
            {
                Console.WriteLine("Buffer Size " + size);
                for (int i = 0; i < 25; i++)
                {
                    timer.Reset();

                    //Test Blocking
                    BlockingTextReader blocking = ParsingTextReader.CreateBlocking(new StreamReader("resources\\nio.ttl"), 4096);
                    timer.Start();
                    int totalBlocking = 0;
                    int read;
                    while (!blocking.EndOfStream)
                    {
                        read = blocking.Read();
                        if (read >= 0)
                        {
                            totalBlocking++;
                        }
                    }
                    timer.Stop();
                    blocking.Close();
                    blockingTime = blockingTime.Add(timer.Elapsed);

                    //Reset
                    timer.Reset();
                    int totalNonBlocking = 0;

                    NonBlockingTextReader nonBlocking = ParsingTextReader.CreateNonBlocking(new StreamReader("resources\\nio.ttl"), 4096);
                    timer.Start();
                    while (!nonBlocking.EndOfStream)
                    {
                        read = nonBlocking.Read();
                        if (read >= 0)
                        {
                            totalNonBlocking++;
                        }
                    }
                    timer.Stop();
                    nonBlocking.Close();
                    nonBlockingTime = nonBlockingTime.Add(timer.Elapsed);

                    Assert.AreEqual(totalBlocking, totalNonBlocking);
                }

                Console.WriteLine();
                Console.WriteLine("Blocking Total Time = " + blockingTime);
                Console.WriteLine("Non-Blocking Total Time = " + nonBlockingTime);
                Console.WriteLine();
                blockingTime    = new TimeSpan();
                nonBlockingTime = new TimeSpan();
            }
        }