Flutter Engine
The Flutter Engine
message_loop_task_queues_benchmark.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/fml/message_loop_task_queues.h"
6
7#include <cassert>
8#include <string>
9#include <thread>
10#include <vector>
11
12#include "flutter/benchmarking/benchmarking.h"
13#include "flutter/fml/synchronization/count_down_latch.h"
14
15namespace fml {
16namespace benchmarking {
17
19 while (state.KeepRunning()) {
21
22 const int num_task_queues = 10;
23 const int num_tasks_per_queue = 100;
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 threads.reserve(num_task_queues);
36 for (int i = 0; i < num_task_queues; i++) {
37 threads.emplace_back([task_runner_id = i, &task_queue, past, &tasks_done,
38 &tasks_registered]() {
39 for (int j = 0; j < num_tasks_per_queue; j++) {
40 task_queue->RegisterTask(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}
66
68
69} // namespace benchmarking
70} // namespace fml
static MessageLoopTaskQueues * GetInstance()
static TimePoint Now()
Definition: time_point.cc:49
AtkStateType state
static void BM_RegisterAndGetTasks(benchmark::State &state)
BENCHMARK(BM_RegisterAndGetTasks)
Definition: ascii_trie.cc:9
std::function< void()> closure
Definition: closure.h:14