| 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" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 void UDPSocketPerfTest::WriteBenchmark(bool use_nonblocking_io) { | 88 void UDPSocketPerfTest::WriteBenchmark(bool use_nonblocking_io) { |
| 89 base::MessageLoopForIO message_loop; | 89 base::MessageLoopForIO message_loop; |
| 90 const uint16_t kPort = 9999; | 90 const uint16_t kPort = 9999; |
| 91 | 91 |
| 92 // Setup the server to listen. | 92 // Setup the server to listen. |
| 93 IPEndPoint bind_address; | 93 IPEndPoint bind_address; |
| 94 CreateUDPAddress("127.0.0.1", kPort, &bind_address); | 94 CreateUDPAddress("127.0.0.1", kPort, &bind_address); |
| 95 std::unique_ptr<UDPServerSocket> server( | 95 std::unique_ptr<UDPServerSocket> server( |
| 96 new UDPServerSocket(nullptr, NetLog::Source())); | 96 new UDPServerSocket(nullptr, NetLog::Source())); |
| 97 #if defined(OS_WIN) | |
| 98 if (use_nonblocking_io) | 97 if (use_nonblocking_io) |
| 99 server->UseNonBlockingIO(); | 98 server->UseNonBlockingIO(); |
| 100 #endif | |
| 101 int rv = server->Listen(bind_address); | 99 int rv = server->Listen(bind_address); |
| 102 ASSERT_THAT(rv, IsOk()); | 100 ASSERT_THAT(rv, IsOk()); |
| 103 | 101 |
| 104 // Setup the client. | 102 // Setup the client. |
| 105 IPEndPoint server_address; | 103 IPEndPoint server_address; |
| 106 CreateUDPAddress("127.0.0.1", kPort, &server_address); | 104 CreateUDPAddress("127.0.0.1", kPort, &server_address); |
| 107 std::unique_ptr<UDPClientSocket> client( | 105 std::unique_ptr<UDPClientSocket> client( |
| 108 new UDPClientSocket(DatagramSocket::DEFAULT_BIND, RandIntCallback(), | 106 new UDPClientSocket(DatagramSocket::DEFAULT_BIND, RandIntCallback(), |
| 109 nullptr, NetLog::Source())); | 107 nullptr, NetLog::Source())); |
| 110 #if defined(OS_WIN) | |
| 111 if (use_nonblocking_io) | 108 if (use_nonblocking_io) |
| 112 client->UseNonBlockingIO(); | 109 client->UseNonBlockingIO(); |
| 113 #endif | |
| 114 rv = client->Connect(server_address); | 110 rv = client->Connect(server_address); |
| 115 EXPECT_THAT(rv, IsOk()); | 111 EXPECT_THAT(rv, IsOk()); |
| 116 | 112 |
| 117 base::RunLoop run_loop; | 113 base::RunLoop run_loop; |
| 118 base::TimeTicks start_ticks = base::TimeTicks::Now(); | 114 base::TimeTicks start_ticks = base::TimeTicks::Now(); |
| 119 int packets = 100000; | 115 int packets = 100000; |
| 120 client->SetSendBufferSize(1024); | 116 client->SetSendBufferSize(1024); |
| 121 WritePacketsToSocket(client.get(), packets, run_loop.QuitClosure()); | 117 WritePacketsToSocket(client.get(), packets, run_loop.QuitClosure()); |
| 122 run_loop.Run(); | 118 run_loop.Run(); |
| 123 | 119 |
| 124 double elapsed = (base::TimeTicks::Now() - start_ticks).InSecondsF(); | 120 double elapsed = (base::TimeTicks::Now() - start_ticks).InSecondsF(); |
| 125 LOG(INFO) << "Write speed: " << packets / 1024 / elapsed << " MB/s"; | 121 LOG(INFO) << "Write speed: " << packets / 1024 / elapsed << " MB/s"; |
| 126 } | 122 } |
| 127 | 123 |
| 128 TEST_F(UDPSocketPerfTest, Write) { | 124 TEST_F(UDPSocketPerfTest, Write) { |
| 129 base::PerfTimeLogger timer("UDP_socket_write"); | 125 base::PerfTimeLogger timer("UDP_socket_write"); |
| 130 WriteBenchmark(false); | 126 WriteBenchmark(false); |
| 131 } | 127 } |
| 132 | 128 |
| 133 #if defined(OS_WIN) | |
| 134 TEST_F(UDPSocketPerfTest, WriteNonBlocking) { | 129 TEST_F(UDPSocketPerfTest, WriteNonBlocking) { |
| 135 base::PerfTimeLogger timer("UDP_socket_write_nonblocking"); | 130 base::PerfTimeLogger timer("UDP_socket_write_nonblocking"); |
| 136 WriteBenchmark(true); | 131 WriteBenchmark(true); |
| 137 } | 132 } |
| 138 #endif | |
| 139 | 133 |
| 140 } // namespace | 134 } // namespace |
| 141 | 135 |
| 142 } // namespace net | 136 } // namespace net |
| OLD | NEW |