| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/test/perf_time_logger.h" | 9 #include "base/test/perf_time_logger.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| 11 #include "net/base/ip_endpoint.h" | 11 #include "net/base/ip_endpoint.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 14 #include "net/log/net_log_source.h" |
| 14 #include "net/test/gtest_util.h" | 15 #include "net/test/gtest_util.h" |
| 15 #include "net/test/net_test_suite.h" | 16 #include "net/test/net_test_suite.h" |
| 16 #include "net/udp/udp_client_socket.h" | 17 #include "net/udp/udp_client_socket.h" |
| 17 #include "net/udp/udp_server_socket.h" | 18 #include "net/udp/udp_server_socket.h" |
| 18 #include "net/udp/udp_socket.h" | 19 #include "net/udp/udp_socket.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "testing/platform_test.h" | 22 #include "testing/platform_test.h" |
| 22 | 23 |
| 23 using net::test::IsOk; | 24 using net::test::IsOk; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 87 } |
| 87 | 88 |
| 88 void UDPSocketPerfTest::WriteBenchmark(bool use_nonblocking_io) { | 89 void UDPSocketPerfTest::WriteBenchmark(bool use_nonblocking_io) { |
| 89 base::MessageLoopForIO message_loop; | 90 base::MessageLoopForIO message_loop; |
| 90 const uint16_t kPort = 9999; | 91 const uint16_t kPort = 9999; |
| 91 | 92 |
| 92 // Setup the server to listen. | 93 // Setup the server to listen. |
| 93 IPEndPoint bind_address; | 94 IPEndPoint bind_address; |
| 94 CreateUDPAddress("127.0.0.1", kPort, &bind_address); | 95 CreateUDPAddress("127.0.0.1", kPort, &bind_address); |
| 95 std::unique_ptr<UDPServerSocket> server( | 96 std::unique_ptr<UDPServerSocket> server( |
| 96 new UDPServerSocket(nullptr, NetLog::Source())); | 97 new UDPServerSocket(nullptr, NetLogSource())); |
| 97 if (use_nonblocking_io) | 98 if (use_nonblocking_io) |
| 98 server->UseNonBlockingIO(); | 99 server->UseNonBlockingIO(); |
| 99 int rv = server->Listen(bind_address); | 100 int rv = server->Listen(bind_address); |
| 100 ASSERT_THAT(rv, IsOk()); | 101 ASSERT_THAT(rv, IsOk()); |
| 101 | 102 |
| 102 // Setup the client. | 103 // Setup the client. |
| 103 IPEndPoint server_address; | 104 IPEndPoint server_address; |
| 104 CreateUDPAddress("127.0.0.1", kPort, &server_address); | 105 CreateUDPAddress("127.0.0.1", kPort, &server_address); |
| 105 std::unique_ptr<UDPClientSocket> client( | 106 std::unique_ptr<UDPClientSocket> client( |
| 106 new UDPClientSocket(DatagramSocket::DEFAULT_BIND, RandIntCallback(), | 107 new UDPClientSocket(DatagramSocket::DEFAULT_BIND, RandIntCallback(), |
| 107 nullptr, NetLog::Source())); | 108 nullptr, NetLogSource())); |
| 108 if (use_nonblocking_io) | 109 if (use_nonblocking_io) |
| 109 client->UseNonBlockingIO(); | 110 client->UseNonBlockingIO(); |
| 110 rv = client->Connect(server_address); | 111 rv = client->Connect(server_address); |
| 111 EXPECT_THAT(rv, IsOk()); | 112 EXPECT_THAT(rv, IsOk()); |
| 112 | 113 |
| 113 base::RunLoop run_loop; | 114 base::RunLoop run_loop; |
| 114 base::TimeTicks start_ticks = base::TimeTicks::Now(); | 115 base::TimeTicks start_ticks = base::TimeTicks::Now(); |
| 115 int packets = 100000; | 116 int packets = 100000; |
| 116 client->SetSendBufferSize(1024); | 117 client->SetSendBufferSize(1024); |
| 117 WritePacketsToSocket(client.get(), packets, run_loop.QuitClosure()); | 118 WritePacketsToSocket(client.get(), packets, run_loop.QuitClosure()); |
| 118 run_loop.Run(); | 119 run_loop.Run(); |
| 119 | 120 |
| 120 double elapsed = (base::TimeTicks::Now() - start_ticks).InSecondsF(); | 121 double elapsed = (base::TimeTicks::Now() - start_ticks).InSecondsF(); |
| 121 LOG(INFO) << "Write speed: " << packets / 1024 / elapsed << " MB/s"; | 122 LOG(INFO) << "Write speed: " << packets / 1024 / elapsed << " MB/s"; |
| 122 } | 123 } |
| 123 | 124 |
| 124 TEST_F(UDPSocketPerfTest, Write) { | 125 TEST_F(UDPSocketPerfTest, Write) { |
| 125 base::PerfTimeLogger timer("UDP_socket_write"); | 126 base::PerfTimeLogger timer("UDP_socket_write"); |
| 126 WriteBenchmark(false); | 127 WriteBenchmark(false); |
| 127 } | 128 } |
| 128 | 129 |
| 129 TEST_F(UDPSocketPerfTest, WriteNonBlocking) { | 130 TEST_F(UDPSocketPerfTest, WriteNonBlocking) { |
| 130 base::PerfTimeLogger timer("UDP_socket_write_nonblocking"); | 131 base::PerfTimeLogger timer("UDP_socket_write_nonblocking"); |
| 131 WriteBenchmark(true); | 132 WriteBenchmark(true); |
| 132 } | 133 } |
| 133 | 134 |
| 134 } // namespace | 135 } // namespace |
| 135 | 136 |
| 136 } // namespace net | 137 } // namespace net |
| OLD | NEW |