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

Side by Side Diff: base/threading/thread_perftest.cc

Issue 668783004: Standardize usage of virtual/override/final in base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatted Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « base/threading/thread_local_unittest.cc ('k') | base/threading/thread_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/base_switches.h" 5 #include "base/base_switches.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/synchronization/condition_variable.h" 10 #include "base/synchronization/condition_variable.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 private: 116 private:
117 base::WaitableEvent done_; 117 base::WaitableEvent done_;
118 }; 118 };
119 119
120 // Class to test task performance by posting empty tasks back and forth. 120 // Class to test task performance by posting empty tasks back and forth.
121 class TaskPerfTest : public ThreadPerfTest { 121 class TaskPerfTest : public ThreadPerfTest {
122 base::Thread* NextThread(int count) { 122 base::Thread* NextThread(int count) {
123 return threads_[count % threads_.size()]; 123 return threads_[count % threads_.size()];
124 } 124 }
125 125
126 virtual void PingPong(int hops) override { 126 void PingPong(int hops) override {
127 if (!hops) { 127 if (!hops) {
128 FinishMeasurement(); 128 FinishMeasurement();
129 return; 129 return;
130 } 130 }
131 NextThread(hops)->message_loop_proxy()->PostTask( 131 NextThread(hops)->message_loop_proxy()->PostTask(
132 FROM_HERE, 132 FROM_HERE,
133 base::Bind( 133 base::Bind(
134 &ThreadPerfTest::PingPong, base::Unretained(this), hops - 1)); 134 &ThreadPerfTest::PingPong, base::Unretained(this), hops - 1));
135 } 135 }
136 }; 136 };
137 137
138 // This tries to test the 'best-case' as well as the 'worst-case' task posting 138 // This tries to test the 'best-case' as well as the 'worst-case' task posting
139 // performance. The best-case keeps one thread alive such that it never yeilds, 139 // performance. The best-case keeps one thread alive such that it never yeilds,
140 // while the worse-case forces a context switch for every task. Four threads are 140 // while the worse-case forces a context switch for every task. Four threads are
141 // used to ensure the threads do yeild (with just two it might be possible for 141 // used to ensure the threads do yeild (with just two it might be possible for
142 // both threads to stay awake if they can signal each other fast enough). 142 // both threads to stay awake if they can signal each other fast enough).
143 TEST_F(TaskPerfTest, TaskPingPong) { 143 TEST_F(TaskPerfTest, TaskPingPong) {
144 RunPingPongTest("1_Task_Threads", 1); 144 RunPingPongTest("1_Task_Threads", 1);
145 RunPingPongTest("4_Task_Threads", 4); 145 RunPingPongTest("4_Task_Threads", 4);
146 } 146 }
147 147
148 148
149 // Same as above, but add observers to test their perf impact. 149 // Same as above, but add observers to test their perf impact.
150 class MessageLoopObserver : public base::MessageLoop::TaskObserver { 150 class MessageLoopObserver : public base::MessageLoop::TaskObserver {
151 public: 151 public:
152 virtual void WillProcessTask(const base::PendingTask& pending_task) override { 152 void WillProcessTask(const base::PendingTask& pending_task) override {}
153 } 153 void DidProcessTask(const base::PendingTask& pending_task) override {}
154 virtual void DidProcessTask(const base::PendingTask& pending_task) override {
155 }
156 }; 154 };
157 MessageLoopObserver message_loop_observer; 155 MessageLoopObserver message_loop_observer;
158 156
159 class TaskObserverPerfTest : public TaskPerfTest { 157 class TaskObserverPerfTest : public TaskPerfTest {
160 public: 158 public:
161 virtual void Init() override { 159 void Init() override {
162 TaskPerfTest::Init(); 160 TaskPerfTest::Init();
163 for (size_t i = 0; i < threads_.size(); i++) { 161 for (size_t i = 0; i < threads_.size(); i++) {
164 threads_[i]->message_loop()->AddTaskObserver(&message_loop_observer); 162 threads_[i]->message_loop()->AddTaskObserver(&message_loop_observer);
165 } 163 }
166 } 164 }
167 }; 165 };
168 166
169 TEST_F(TaskObserverPerfTest, TaskPingPong) { 167 TEST_F(TaskObserverPerfTest, TaskPingPong) {
170 RunPingPongTest("1_Task_Threads_With_Observer", 1); 168 RunPingPongTest("1_Task_Threads_With_Observer", 1);
171 RunPingPongTest("4_Task_Threads_With_Observer", 4); 169 RunPingPongTest("4_Task_Threads_With_Observer", 4);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 typedef EventPerfTest<PthreadEvent> PthreadEventPerfTest; 303 typedef EventPerfTest<PthreadEvent> PthreadEventPerfTest;
306 TEST_F(PthreadEventPerfTest, EventPingPong) { 304 TEST_F(PthreadEventPerfTest, EventPingPong) {
307 RunPingPongTest("4_PthreadCondVar_Threads", 4); 305 RunPingPongTest("4_PthreadCondVar_Threads", 4);
308 } 306 }
309 307
310 #endif 308 #endif
311 309
312 } // namespace 310 } // namespace
313 311
314 } // namespace base 312 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/thread_local_unittest.cc ('k') | base/threading/thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698