| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/stringprintf.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "mojo/public/cpp/bindings/binding.h" | 14 #include "mojo/public/cpp/bindings/binding.h" |
| 14 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" | 15 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" |
| 15 #include "mojo/public/cpp/bindings/lib/message_builder.h" | 16 #include "mojo/public/cpp/bindings/lib/message_builder.h" |
| 16 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" | 17 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
| 18 #include "mojo/public/cpp/bindings/lib/serialization.h" |
| 17 #include "mojo/public/cpp/bindings/message.h" | 19 #include "mojo/public/cpp/bindings/message.h" |
| 18 #include "mojo/public/cpp/test_support/test_support.h" | 20 #include "mojo/public/cpp/test_support/test_support.h" |
| 19 #include "mojo/public/cpp/test_support/test_utils.h" | 21 #include "mojo/public/cpp/test_support/test_utils.h" |
| 20 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h" | 22 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 24 |
| 23 namespace mojo { | 25 namespace mojo { |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 const double kMojoTicksPerSecond = 1000000.0; | 28 const double kMojoTicksPerSecond = 1000000.0; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 CHECK_EQ(kIterations[i], receiver.counter()); | 275 CHECK_EQ(kIterations[i], receiver.counter()); |
| 274 | 276 |
| 275 if (i == 1) { | 277 if (i == 1) { |
| 276 test::LogPerfResult("MultiplexRouterDispatchCost", nullptr, | 278 test::LogPerfResult("MultiplexRouterDispatchCost", nullptr, |
| 277 kIterations[i] / duration.InSecondsF(), | 279 kIterations[i] / duration.InSecondsF(), |
| 278 "times/second"); | 280 "times/second"); |
| 279 } | 281 } |
| 280 } | 282 } |
| 281 } | 283 } |
| 282 | 284 |
| 283 } // namespace | 285 void TestStringDeserializationInternal(bool utf8_check, |
| 286 const std::string& input, |
| 287 size_t iterations) { |
| 288 auto data = mojo::internal::SerializeString(input); |
| 289 std::string output; |
| 290 for (size_t i = 0; i < 10; ++i) { |
| 291 EXPECT_TRUE(mojo::internal::DeserializeString(utf8_check, data, &output)); |
| 292 } |
| 293 EXPECT_EQ(input, output); |
| 294 |
| 295 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 296 for (size_t i = 0; i < iterations; ++i) { |
| 297 EXPECT_TRUE(mojo::internal::DeserializeString(utf8_check, data, &output)); |
| 298 } |
| 299 base::TimeTicks end_time = base::TimeTicks::Now(); |
| 300 base::TimeDelta duration = end_time - start_time; |
| 301 |
| 302 test::LogPerfResult(utf8_check ? "DeserializeString_Utf8Check" |
| 303 : "DeserializeString_NoUtf8Check", |
| 304 base::StringPrintf("%lu", input.size()).c_str(), |
| 305 iterations / duration.InSecondsF(), "times/second"); |
| 306 } |
| 307 |
| 308 void TestStringDeserialization(const std::string& input, size_t iterations) { |
| 309 TestStringDeserializationInternal(false, input, iterations); |
| 310 TestStringDeserializationInternal(true, input, iterations); |
| 311 } |
| 312 |
| 313 std::string CreateASCIIString(size_t length) { |
| 314 std::string result(length, 0); |
| 315 for (size_t i = 0; i < length; ++i) { |
| 316 result[i] = i % 128; |
| 317 } |
| 318 EXPECT_EQ(length, result.size()); |
| 319 return result; |
| 320 } |
| 321 |
| 322 TEST_F(MojoBindingsPerftest, String) { |
| 323 TestStringDeserialization(CreateASCIIString(8), 10000000); |
| 324 TestStringDeserialization(CreateASCIIString(128), 10000000); |
| 325 TestStringDeserialization(CreateASCIIString(1024), 10000000); |
| 326 } |
| 327 |
| 328 } |
| 284 } // namespace mojo | 329 } // namespace mojo |
| OLD | NEW |