Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1368)

Unified Diff: mojo/environment/async_wait_perftest.cc

Issue 2142393002: Add perf tests for async waits using base::MessageLoop. (Closed) Base URL: https://github.com/domokit/mojo.git@work791_async_waiter_perftest
Patch Set: gah Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/environment/BUILD.gn ('k') | mojo/tools/get_test_list.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/environment/async_wait_perftest.cc
diff --git a/mojo/environment/async_wait_perftest.cc b/mojo/environment/async_wait_perftest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8614b8557c0de9fc5fb37119a8469825e8c71231
--- /dev/null
+++ b/mojo/environment/async_wait_perftest.cc
@@ -0,0 +1,78 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file has perf tests for async waits using |base::MessageLoop| (i.e., the
+// "Chromium" |Environment|).
+
+#include <stdint.h>
+
+#include <functional>
+#include <memory>
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop/message_loop.h"
+#include "base/strings/stringprintf.h"
+#include "base/test/perf_log.h"
+#include "base/time/time.h"
+#include "mojo/message_pump/message_pump_mojo.h"
+#include "mojo/public/c/environment/tests/async_waiter_perftest_helpers.h"
+#include "mojo/public/cpp/environment/environment.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace mojo {
+namespace {
+
+constexpr int64_t kPerftestTimeMicroseconds = 3 * 1000000;
+
+void QuitMessageLoopNow() {
+ base::MessageLoop::current()->QuitNow();
+}
+
+void SingleThreadedTestHelper(
+ const char* name,
+ std::function<std::unique_ptr<base::MessageLoop>()> make_message_loop) {
+ for (uint32_t num_handles = 1u; num_handles <= 10000u; num_handles *= 10u) {
+ auto message_loop = make_message_loop();
+
+ base::TimeTicks start_time;
+ base::TimeTicks end_time;
+ uint64_t raw_result = test::DoAsyncWaiterPerfTest(
+ Environment::GetDefaultAsyncWaiter(), num_handles,
+ [&start_time, &end_time]() {
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, base::Bind(&QuitMessageLoopNow),
+ base::TimeDelta::FromMicroseconds(kPerftestTimeMicroseconds));
+ start_time = base::TimeTicks::Now();
+ base::MessageLoop::current()->Run();
+ end_time = base::TimeTicks::Now();
+ });
+
+ double result =
+ static_cast<double>(raw_result) / (end_time - start_time).InSecondsF();
+ base::LogPerfResult(
+ base::StringPrintf("%s/%u", name, static_cast<unsigned>(num_handles))
+ .c_str(),
+ result, "callbacks/second");
+ }
+}
+
+TEST(AsyncWaitPerfTest, SingleThreaded_DefaultMessagePump) {
+ SingleThreadedTestHelper(
+ "AsyncWaitPerfTest.SingleThreaded_DefaultMessagePump", []() {
+ return std::unique_ptr<base::MessageLoop>(new base::MessageLoop());
+ });
+}
+
+TEST(AsyncWaitPerfTest, SingleThreaded_MessagePumpMojo) {
+ SingleThreadedTestHelper(
+ "AsyncWaitPerfTest.SingleThreaded_MessagePumpMojo", []() {
+ return std::unique_ptr<base::MessageLoop>(new base::MessageLoop(
+ make_scoped_ptr(new common::MessagePumpMojo())));
+ });
+}
+
+} // namespace
+} // namespace mojo
« no previous file with comments | « mojo/environment/BUILD.gn ('k') | mojo/tools/get_test_list.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698