Flutter Engine
fml::benchmarking Namespace Reference

Functions

static void BM_RegisterAndGetTasks (benchmark::State &state)
 
 BENCHMARK (BM_RegisterAndGetTasks)
 

Function Documentation

◆ BENCHMARK()

fml::benchmarking::BENCHMARK ( BM_RegisterAndGetTasks  )

Referenced by BM_RegisterAndGetTasks().

◆ BM_RegisterAndGetTasks()

static void fml::benchmarking::BM_RegisterAndGetTasks ( benchmark::State &  state)
static

Definition at line 18 of file message_loop_task_queues_benchmark.cc.

References BENCHMARK(), fml::CountDownLatch::CountDown(), fml::MessageLoopTaskQueues::GetInstance(), fml::TimePoint::Now(), and fml::CountDownLatch::Wait().

18  { // NOLINT
19  while (state.KeepRunning()) {
20  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
21 
22  const int num_task_queues = 10;
23  const int num_tasks_per_queue = 100;
24  const fml::TimePoint past = fml::TimePoint::Now();
25 
26  for (int i = 0; i < num_task_queues; i++) {
27  task_queue->CreateTaskQueue();
28  }
29 
30  std::vector<std::thread> threads;
31 
32  CountDownLatch tasks_registered(num_task_queues);
33  CountDownLatch tasks_done(num_task_queues);
34 
35  for (int i = 0; i < num_task_queues; i++) {
36  threads.emplace_back([task_runner_id = i, &task_queue, past, &tasks_done,
37  &tasks_registered]() {
38  for (int j = 0; j < num_tasks_per_queue; j++) {
39  task_queue->RegisterTask(
40  TaskQueueId(task_runner_id), [] {}, past);
41  }
42  tasks_registered.CountDown();
43  tasks_registered.Wait();
44  const auto now = fml::TimePoint::Now();
45  int num_invocations = 0;
46  for (;;) {
47  fml::closure invocation =
48  task_queue->GetNextTaskToRun(TaskQueueId(task_runner_id), now);
49  if (!invocation) {
50  break;
51  }
52  num_invocations++;
53  }
54  assert(num_invocations == num_tasks_per_queue);
55  tasks_done.CountDown();
56  });
57  }
58 
59  tasks_done.Wait();
60 
61  for (auto& thread : threads) {
62  thread.join();
63  }
64  }
65 }
std::function< void()> closure
Definition: closure.h:14
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static TimePoint Now()
Definition: time_point.cc:26