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

Unified Diff: cc/base/worker_pool_perftest.cc

Issue 14689004: Re-land: cc: Cancel and re-prioritize worker pool tasks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added support for dependencies and tests. Created 7 years, 7 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
Index: cc/base/worker_pool_perftest.cc
diff --git a/cc/base/worker_pool_perftest.cc b/cc/base/worker_pool_perftest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bcbfe09ca8ff184166b65fa811bd3d3c7aa24f04
--- /dev/null
+++ b/cc/base/worker_pool_perftest.cc
@@ -0,0 +1,111 @@
+// Copyright 2013 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.
+
+#include "cc/base/worker_pool.h"
+
+#include "base/time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace cc {
+
+namespace {
+
+static const int kTimeLimitMillis = 1000;
+static const int kWarmupRuns = 5;
+static const int kTimeCheckInterval = 1000;
+
+class WorkerPoolPerfTest : public testing::Test {
+ public:
+ WorkerPoolPerfTest() : num_runs_(0) {}
+
+ // Overridden from testing::Test:
+ virtual void SetUp() OVERRIDE {}
+ virtual void TearDown() OVERRIDE {}
+
+ void EndTest() {
+ elapsed_ = base::TimeTicks::HighResNow() - start_time_;
+ }
+
+ void AfterTest(const std::string test_name) {
+ // Format matches chrome/test/perf/perf_test.h:PrintResult
+ printf("*RESULT %s: %.2f runs/s\n",
+ test_name.c_str(),
+ num_runs_ / elapsed_.InSecondsF());
+ }
+
+ void BuildGraph(internal::WorkerPoolTaskDependency* graph,
+ unsigned current_depth,
+ unsigned max_depth,
+ unsigned num_children_per_node) {
+ for (unsigned i = 0; i < num_children_per_node; ++i) {
+ internal::WorkerPoolTaskDependency sub_graph;
+ if (current_depth < max_depth) {
+ BuildGraph(&sub_graph,
+ current_depth + 1,
+ max_depth,
+ num_children_per_node);
+ }
+ internal::WorkerPoolTaskDependency::Create(NULL, graph, &sub_graph);
+ }
+ }
+
+ void BuildGraph(unsigned max_depth, unsigned num_children_per_node) {
+ internal::WorkerPoolTaskDependency graph;
+ DCHECK(max_depth);
+ BuildGraph(&graph, 1, max_depth, num_children_per_node);
+ graph_.Swap(&graph);
+ }
+
+ bool DidRun() {
+ ++num_runs_;
+ if (num_runs_ == kWarmupRuns)
+ start_time_ = base::TimeTicks::HighResNow();
+
+ if (!start_time_.is_null() && (num_runs_ % kTimeCheckInterval) == 0) {
+ base::TimeDelta elapsed = base::TimeTicks::HighResNow() - start_time_;
+ if (elapsed >= base::TimeDelta::FromMilliseconds(kTimeLimitMillis)) {
+ elapsed_ = elapsed;
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ void RunGraphTraversalTest(const std::string test_name) {
+ num_runs_ = 0;
+ do {
+ for (internal::WorkerPoolTaskGraph::Iterator it(&graph_); it; ++it);
+ } while (DidRun());
+
+ AfterTest(test_name);
+ }
+
+ protected:
+ internal::WorkerPoolTaskGraph graph_;
+ base::TimeTicks start_time_;
+ base::TimeDelta elapsed_;
+ int num_runs_;
+};
+
+TEST_F(WorkerPoolPerfTest, GraphTraversal) {
+ BuildGraph(1, 10);
+ RunGraphTraversalTest("graph_traversal_1_10");
+ BuildGraph(1, 1000);
+ RunGraphTraversalTest("graph_traversal_1_1000");
+ BuildGraph(2, 10);
+ RunGraphTraversalTest("graph_traversal_2_10");
+ BuildGraph(5, 5);
+ RunGraphTraversalTest("graph_traversal_5_5");
+ BuildGraph(10, 2);
+ RunGraphTraversalTest("graph_traversal_10_2");
+ BuildGraph(10, 1);
+ RunGraphTraversalTest("graph_traversal_10_1");
+ BuildGraph(1000, 1);
+ RunGraphTraversalTest("graph_traversal_1000_1");
+}
+
+} // namespace
+
+} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698