| OLD | NEW |
| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/format_macros.h" | 6 #include "base/format_macros.h" |
| 7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/synchronization/condition_variable.h" | 9 #include "base/synchronization/condition_variable.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace base { | 22 namespace base { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 class ScheduleWorkTest : public testing::Test { | 25 class ScheduleWorkTest : public testing::Test { |
| 26 public: | 26 public: |
| 27 ScheduleWorkTest() : counter_(0) {} | 27 ScheduleWorkTest() : counter_(0) {} |
| 28 | 28 |
| 29 void Increment(uint64_t amount) { counter_ += amount; } | 29 void Increment(uint64_t amount) { counter_ += amount; } |
| 30 | 30 |
| 31 void Schedule(int index) { | 31 void Schedule(int index) { |
| 32 base::TimeTicks start = base::TimeTicks::HighResNow(); | 32 base::TimeTicks start = base::TimeTicks::Now(); |
| 33 base::TimeTicks thread_start; | 33 base::TimeTicks thread_start; |
| 34 if (TimeTicks::IsThreadNowSupported()) | 34 if (TimeTicks::IsThreadNowSupported()) |
| 35 thread_start = base::TimeTicks::ThreadNow(); | 35 thread_start = base::TimeTicks::ThreadNow(); |
| 36 base::TimeDelta minimum = base::TimeDelta::Max(); | 36 base::TimeDelta minimum = base::TimeDelta::Max(); |
| 37 base::TimeDelta maximum = base::TimeDelta(); | 37 base::TimeDelta maximum = base::TimeDelta(); |
| 38 base::TimeTicks now, lastnow = start; | 38 base::TimeTicks now, lastnow = start; |
| 39 uint64_t schedule_calls = 0u; | 39 uint64_t schedule_calls = 0u; |
| 40 do { | 40 do { |
| 41 for (size_t i = 0; i < kBatchSize; ++i) { | 41 for (size_t i = 0; i < kBatchSize; ++i) { |
| 42 target_message_loop()->ScheduleWork(); | 42 target_message_loop()->ScheduleWork(); |
| 43 schedule_calls++; | 43 schedule_calls++; |
| 44 } | 44 } |
| 45 now = base::TimeTicks::HighResNow(); | 45 now = base::TimeTicks::Now(); |
| 46 base::TimeDelta laptime = now - lastnow; | 46 base::TimeDelta laptime = now - lastnow; |
| 47 lastnow = now; | 47 lastnow = now; |
| 48 minimum = std::min(minimum, laptime); | 48 minimum = std::min(minimum, laptime); |
| 49 maximum = std::max(maximum, laptime); | 49 maximum = std::max(maximum, laptime); |
| 50 } while (now - start < base::TimeDelta::FromSeconds(kTargetTimeSec)); | 50 } while (now - start < base::TimeDelta::FromSeconds(kTargetTimeSec)); |
| 51 | 51 |
| 52 scheduling_times_[index] = now - start; | 52 scheduling_times_[index] = now - start; |
| 53 if (TimeTicks::IsThreadNowSupported()) | 53 if (TimeTicks::IsThreadNowSupported()) |
| 54 scheduling_thread_times_[index] = | 54 scheduling_thread_times_[index] = |
| 55 base::TimeTicks::ThreadNow() - thread_start; | 55 base::TimeTicks::ThreadNow() - thread_start; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 void Run(Delegate* delegate) override {} | 235 void Run(Delegate* delegate) override {} |
| 236 | 236 |
| 237 void Quit() override {} | 237 void Quit() override {} |
| 238 void ScheduleWork() override {} | 238 void ScheduleWork() override {} |
| 239 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override {} | 239 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override {} |
| 240 }; | 240 }; |
| 241 | 241 |
| 242 class PostTaskTest : public testing::Test { | 242 class PostTaskTest : public testing::Test { |
| 243 public: | 243 public: |
| 244 void Run(int batch_size, int tasks_per_reload) { | 244 void Run(int batch_size, int tasks_per_reload) { |
| 245 base::TimeTicks start = base::TimeTicks::HighResNow(); | 245 base::TimeTicks start = base::TimeTicks::Now(); |
| 246 base::TimeTicks now; | 246 base::TimeTicks now; |
| 247 MessageLoop loop(scoped_ptr<MessagePump>(new FakeMessagePump)); | 247 MessageLoop loop(scoped_ptr<MessagePump>(new FakeMessagePump)); |
| 248 scoped_refptr<internal::IncomingTaskQueue> queue( | 248 scoped_refptr<internal::IncomingTaskQueue> queue( |
| 249 new internal::IncomingTaskQueue(&loop)); | 249 new internal::IncomingTaskQueue(&loop)); |
| 250 uint32_t num_posted = 0; | 250 uint32_t num_posted = 0; |
| 251 do { | 251 do { |
| 252 for (int i = 0; i < batch_size; ++i) { | 252 for (int i = 0; i < batch_size; ++i) { |
| 253 for (int j = 0; j < tasks_per_reload; ++j) { | 253 for (int j = 0; j < tasks_per_reload; ++j) { |
| 254 queue->AddToIncomingQueue( | 254 queue->AddToIncomingQueue( |
| 255 FROM_HERE, base::Bind(&DoNothing), base::TimeDelta(), false); | 255 FROM_HERE, base::Bind(&DoNothing), base::TimeDelta(), false); |
| 256 num_posted++; | 256 num_posted++; |
| 257 } | 257 } |
| 258 TaskQueue loop_local_queue; | 258 TaskQueue loop_local_queue; |
| 259 queue->ReloadWorkQueue(&loop_local_queue); | 259 queue->ReloadWorkQueue(&loop_local_queue); |
| 260 while (!loop_local_queue.empty()) { | 260 while (!loop_local_queue.empty()) { |
| 261 PendingTask t = loop_local_queue.front(); | 261 PendingTask t = loop_local_queue.front(); |
| 262 loop_local_queue.pop(); | 262 loop_local_queue.pop(); |
| 263 loop.RunTask(t); | 263 loop.RunTask(t); |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 now = base::TimeTicks::HighResNow(); | 267 now = base::TimeTicks::Now(); |
| 268 } while (now - start < base::TimeDelta::FromSeconds(5)); | 268 } while (now - start < base::TimeDelta::FromSeconds(5)); |
| 269 std::string trace = StringPrintf("%d_tasks_per_reload", tasks_per_reload); | 269 std::string trace = StringPrintf("%d_tasks_per_reload", tasks_per_reload); |
| 270 perf_test::PrintResult( | 270 perf_test::PrintResult( |
| 271 "task", | 271 "task", |
| 272 "", | 272 "", |
| 273 trace, | 273 trace, |
| 274 (now - start).InMicroseconds() / static_cast<double>(num_posted), | 274 (now - start).InMicroseconds() / static_cast<double>(num_posted), |
| 275 "us/task", | 275 "us/task", |
| 276 true); | 276 true); |
| 277 } | 277 } |
| 278 }; | 278 }; |
| 279 | 279 |
| 280 TEST_F(PostTaskTest, OneTaskPerReload) { | 280 TEST_F(PostTaskTest, OneTaskPerReload) { |
| 281 Run(10000, 1); | 281 Run(10000, 1); |
| 282 } | 282 } |
| 283 | 283 |
| 284 TEST_F(PostTaskTest, TenTasksPerReload) { | 284 TEST_F(PostTaskTest, TenTasksPerReload) { |
| 285 Run(10000, 10); | 285 Run(10000, 10); |
| 286 } | 286 } |
| 287 | 287 |
| 288 TEST_F(PostTaskTest, OneHundredTasksPerReload) { | 288 TEST_F(PostTaskTest, OneHundredTasksPerReload) { |
| 289 Run(1000, 100); | 289 Run(1000, 100); |
| 290 } | 290 } |
| 291 | 291 |
| 292 } // namespace | 292 } // namespace |
| 293 } // namespace base | 293 } // namespace base |
| OLD | NEW |