| 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 "platform/scheduler/base/task_queue_manager.h" | 5 #include "platform/scheduler/base/task_queue_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 i++) { | 120 i++) { |
| 121 // Choose a queue weighted towards queue 0. | 121 // Choose a queue weighted towards queue 0. |
| 122 unsigned int queue = num_tasks_to_post_ % (num_queues_ + 1); | 122 unsigned int queue = num_tasks_to_post_ % (num_queues_ + 1); |
| 123 if (queue == num_queues_) { | 123 if (queue == num_queues_) { |
| 124 queue = 0; | 124 queue = 0; |
| 125 } | 125 } |
| 126 // Simulate a mix of short and longer delays. | 126 // Simulate a mix of short and longer delays. |
| 127 unsigned int delay = | 127 unsigned int delay = |
| 128 num_tasks_to_post_ % 2 ? 1 : (10 + num_tasks_to_post_ % 10); | 128 num_tasks_to_post_ % 2 ? 1 : (10 + num_tasks_to_post_ % 10); |
| 129 queues_[queue]->PostDelayedTask( | 129 queues_[queue]->PostDelayedTask( |
| 130 FROM_HERE, base::Bind(&TaskQueueManagerPerfTest::TestDelayedTask, | 130 FROM_HERE, |
| 131 base::Unretained(this)), | 131 base::Bind(&TaskQueueManagerPerfTest::TestDelayedTask, |
| 132 base::Unretained(this)), |
| 132 base::TimeDelta::FromMilliseconds(delay)); | 133 base::TimeDelta::FromMilliseconds(delay)); |
| 133 num_tasks_in_flight_++; | 134 num_tasks_in_flight_++; |
| 134 num_tasks_to_post_--; | 135 num_tasks_to_post_--; |
| 135 } | 136 } |
| 136 } | 137 } |
| 137 | 138 |
| 138 void ResetAndCallTestDelayedTask(unsigned int num_tasks_to_run) { | 139 void ResetAndCallTestDelayedTask(unsigned int num_tasks_to_run) { |
| 139 num_tasks_in_flight_ = 1; | 140 num_tasks_in_flight_ = 1; |
| 140 num_tasks_to_post_ = num_tasks_to_run; | 141 num_tasks_to_post_ = num_tasks_to_run; |
| 141 num_tasks_to_run_ = num_tasks_to_run; | 142 num_tasks_to_run_ = num_tasks_to_run; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 Benchmark("run 10000 delayed tasks with eight queues", | 217 Benchmark("run 10000 delayed tasks with eight queues", |
| 217 base::Bind(&TaskQueueManagerPerfTest::ResetAndCallTestDelayedTask, | 218 base::Bind(&TaskQueueManagerPerfTest::ResetAndCallTestDelayedTask, |
| 218 base::Unretained(this), 10000)); | 219 base::Unretained(this), 10000)); |
| 219 } | 220 } |
| 220 | 221 |
| 221 // TODO(alexclarke): Add additional tests with different mixes of non-delayed vs | 222 // TODO(alexclarke): Add additional tests with different mixes of non-delayed vs |
| 222 // delayed tasks. | 223 // delayed tasks. |
| 223 | 224 |
| 224 } // namespace scheduler | 225 } // namespace scheduler |
| 225 } // namespace blink | 226 } // namespace blink |
| OLD | NEW |