Exemplo n.º 1
0
        public OutputBandwithTestResults Test(int size, int iterationsCount)
        {
            GC.Collect(1);
            int sentCounter     = _channel.BytesSent;
            int receivedCounter = _channel.BytesReceived;

            _contract.SubscribeForSayCalled(iterationsCount);
            var allDataReceivedByServer = new ManualResetEvent(false);

            _contract.SaysCallsCountReceived += () => allDataReceivedByServer.Set();

            var packet = _dataGenerator(size);

            var send           = new Stopwatch();
            var sendandReceive = new Stopwatch();

            send.Start();
            sendandReceive.Start();

            _sendProcedure(iterationsCount, packet);

            send.Stop();
            allDataReceivedByServer.WaitOne();
            sendandReceive.Stop();

            _contract.SaysCallsCountReceived = null;

            return(new OutputBandwithTestResults
            {
                ElaspedMilisecondsForSendOnly = send.ElapsedMilliseconds,
                ElaspedMilisecondsForSendAndReceive = sendandReceive.ElapsedMilliseconds,
                Iterations = iterationsCount,
                Size = size,
                TotalSent = _channel.BytesSent - sentCounter,
                TotalReceived = _channel.BytesReceived - receivedCounter,
            });
        }
Exemplo n.º 2
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");
        }