private void SendBenchmark(SimplSocketClient client) { Log("*** SendBenchmark ***"); var rnd = new Random(); var bufferSizes = new[] { 1, 10, 100, 1000 }; var length = 0; for (var test = 0; test < 4; test++) { byte[] randomData = new byte[bufferSizes[test] * 512]; length += randomData.Length; rnd.NextBytes(randomData); var countPerIteration = 100; var watch = Stopwatch.StartNew(); for (var i = 0; i < countPerIteration; i++) { randomData = new byte[bufferSizes[test] * 512]; if (!client.IsConnected()) { client.Connect(new IPEndPoint(IPAddress.Loopback, 5000)); } client.Send(randomData); } watch.Stop(); var speed = (countPerIteration * length) / (watch.ElapsedMilliseconds / 1000.0); var scaledSpeed = ScaledSpeed(speed); Log($"{countPerIteration}x{length}: {watch.ElapsedMilliseconds}ms = {scaledSpeed} "); } }
private void SendFromPoolAndReceiveCheck(SimplSocketClient client) { Log("*** SendFromPoolAndReceiveCheck ***"); var rnd = new Random(); var randomData = PooledMessage.Rent(1000 * 512); rnd.NextBytes(randomData.Content); if (!client.IsConnected()) { client.Connect(new IPEndPoint(IPAddress.Loopback, 5000)); } var outputData = client.SendReceive(randomData); var same = true; for (int i = 0; i < outputData.Length; i++) { if (outputData.Content[i] != randomData.Content[i]) { same = false; break; } } randomData.Return(); outputData.Return(); Log(same ? "data is same" : "Data is not the same"); }
private void SendAndReceiveCheck(SimplSocketClient client) { Log("*** SendAndReceiveCheck ***"); var rnd = new Random(); byte[] randomData = new byte[1000 * 512]; rnd.NextBytes(randomData); if (!client.IsConnected()) { client.Connect(new IPEndPoint(IPAddress.Loopback, 5000)); } var outputData = client.SendReceive(randomData); if (outputData == null) { Log("No answer received"); return; } var same = true; for (int i = 0; i < outputData.Length; i++) { if (outputData.Content[i] != randomData[i]) { same = false; break; } } // We need to return the output data to pool outputData.Return(); Log(same?"data is same":"Data is not the same"); }
private void SendFromPoolAndReceiveBenchmark(SimplSocketClient client) { Log("*** SendFromPoolAndReceiveBenchmark ***"); var rnd = new Random(); var bufferSizes = new[] { 1, 10, 100, 1000 }; var length = 0; for (var test = 0; test < 4; test++) { var randomData = PooledMessage.Rent(bufferSizes[test] * 512); length += randomData.Length; rnd.NextBytes(randomData.Content); var countPerIteration = 100; var watch = Stopwatch.StartNew(); for (var i = 0; i < countPerIteration; i++) { if (!client.IsConnected()) { client.Connect(new IPEndPoint(IPAddress.Loopback, 5000)); } var response = client.SendReceive(randomData); if (response == null) { Log("No response "); } else { response.Return(); } } watch.Stop(); var speed = (countPerIteration * length) / (watch.ElapsedMilliseconds / 1000.0); var scaledSpeed = ScaledSpeed(speed); Log($"{countPerIteration}x{length}: {watch.ElapsedMilliseconds}ms = {scaledSpeed} "); randomData.Return(); } }
public bool IsConnected() { return(_simplSocketClient.IsConnected()); }