Exemplo n.º 1
0
        public void MeasureOutputOverhead()
        {
            _output.WriteLine("Output overhead measuring");

            int sentCounter     = _channel.BytesSent;
            int receivedCounter = _channel.BytesReceived;


            int iterationsCount = 100000;

            _proxy.SubscribeForSayCalled(iterationsCount);

            ManualResetEvent mre = new ManualResetEvent(false);

            _proxy.SaysCallsCountReceived += () => mre.Set();
            Stopwatch sw = new Stopwatch();

            sw.Start();
            //Act:
            for (int i = 0; i < iterationsCount; i++)
            {
                _proxy.SayNothing();
            }

            mre.WaitOne();
            sw.Stop();
            _proxy.SaysCallsCountReceived = null;

            _output.WriteLine(
                $"    Delay: {(sw.ElapsedMilliseconds * 1000) / (double)iterationsCount} microseconds");
            _output.WriteLine(
                $"    Ticks: {sw.ElapsedTicks / iterationsCount}");
            _output.WriteLine(
                $"    Sent by client per transaction: {(_channel.BytesSent - sentCounter) / iterationsCount} b");
            _output.WriteLine(
                $"    Received by client per transaction: {(_channel.BytesReceived - receivedCounter) / iterationsCount} b");
        }