| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // This tests the performance of the C API. | 5 // This tests the performance of the C API. |
| 6 | 6 |
| 7 #include "mojo/public/c/system/core.h" | 7 #include "mojo/public/c/system/core.h" |
| 8 | 8 |
| 9 #include <assert.h> | 9 #include <assert.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "mojo/public/cpp/utility/thread.h" | 22 #include "mojo/public/cpp/utility/thread.h" |
| 23 #endif // !defined(WIN32) | 23 #endif // !defined(WIN32) |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 #if !defined(WIN32) | 27 #if !defined(WIN32) |
| 28 class MessagePipeWriterThread : public mojo::Thread { | 28 class MessagePipeWriterThread : public mojo::Thread { |
| 29 public: | 29 public: |
| 30 MessagePipeWriterThread(MojoHandle handle, uint32_t num_bytes) | 30 MessagePipeWriterThread(MojoHandle handle, uint32_t num_bytes) |
| 31 : handle_(handle), num_bytes_(num_bytes), num_writes_(0) {} | 31 : handle_(handle), num_bytes_(num_bytes), num_writes_(0) {} |
| 32 virtual ~MessagePipeWriterThread() {} | 32 ~MessagePipeWriterThread() override {} |
| 33 | 33 |
| 34 virtual void Run() override { | 34 void Run() override { |
| 35 char buffer[10000]; | 35 char buffer[10000]; |
| 36 assert(num_bytes_ <= sizeof(buffer)); | 36 assert(num_bytes_ <= sizeof(buffer)); |
| 37 | 37 |
| 38 // TODO(vtl): Should I throttle somehow? | 38 // TODO(vtl): Should I throttle somehow? |
| 39 for (;;) { | 39 for (;;) { |
| 40 MojoResult result = MojoWriteMessage( | 40 MojoResult result = MojoWriteMessage( |
| 41 handle_, buffer, num_bytes_, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE); | 41 handle_, buffer, num_bytes_, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE); |
| 42 if (result == MOJO_RESULT_OK) { | 42 if (result == MOJO_RESULT_OK) { |
| 43 num_writes_++; | 43 num_writes_++; |
| 44 continue; | 44 continue; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 60 const uint32_t num_bytes_; | 60 const uint32_t num_bytes_; |
| 61 int64_t num_writes_; | 61 int64_t num_writes_; |
| 62 | 62 |
| 63 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipeWriterThread); | 63 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipeWriterThread); |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 class MessagePipeReaderThread : public mojo::Thread { | 66 class MessagePipeReaderThread : public mojo::Thread { |
| 67 public: | 67 public: |
| 68 explicit MessagePipeReaderThread(MojoHandle handle) | 68 explicit MessagePipeReaderThread(MojoHandle handle) |
| 69 : handle_(handle), num_reads_(0) {} | 69 : handle_(handle), num_reads_(0) {} |
| 70 virtual ~MessagePipeReaderThread() {} | 70 ~MessagePipeReaderThread() override {} |
| 71 | 71 |
| 72 virtual void Run() override { | 72 void Run() override { |
| 73 char buffer[10000]; | 73 char buffer[10000]; |
| 74 | 74 |
| 75 for (;;) { | 75 for (;;) { |
| 76 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); | 76 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); |
| 77 MojoResult result = MojoReadMessage( | 77 MojoResult result = MojoReadMessage( |
| 78 handle_, buffer, &num_bytes, NULL, NULL, MOJO_READ_MESSAGE_FLAG_NONE); | 78 handle_, buffer, &num_bytes, NULL, NULL, MOJO_READ_MESSAGE_FLAG_NONE); |
| 79 if (result == MOJO_RESULT_OK) { | 79 if (result == MOJO_RESULT_OK) { |
| 80 num_reads_++; | 80 num_reads_++; |
| 81 continue; | 81 continue; |
| 82 } | 82 } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 DoMessagePipeThreadedTest(1u, 1u, 10000u); | 323 DoMessagePipeThreadedTest(1u, 1u, 10000u); |
| 324 | 324 |
| 325 DoMessagePipeThreadedTest(3u, 3u, 10u); | 325 DoMessagePipeThreadedTest(3u, 3u, 10u); |
| 326 // 100 was done above. | 326 // 100 was done above. |
| 327 DoMessagePipeThreadedTest(3u, 3u, 1000u); | 327 DoMessagePipeThreadedTest(3u, 3u, 1000u); |
| 328 DoMessagePipeThreadedTest(3u, 3u, 10000u); | 328 DoMessagePipeThreadedTest(3u, 3u, 10000u); |
| 329 } | 329 } |
| 330 #endif // !defined(WIN32) | 330 #endif // !defined(WIN32) |
| 331 | 331 |
| 332 } // namespace | 332 } // namespace |
| OLD | NEW |