Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9cea138

Browse files
committed
Split AddRect/GetRects benchmarks
1 parent 2d0683f commit 9cea138

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

display_list/benchmarking/dl_region_benchmarks.cc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,27 @@ void RunAddRectsBenchmark(benchmark::State& state, int maxSize) {
9393

9494
while (state.KeepRunning()) {
9595
Region region(rects);
96+
}
97+
}
98+
99+
template <typename Region>
100+
void RunGetRectsBenchmark(benchmark::State& state, int maxSize) {
101+
std::random_device d;
102+
std::seed_seq seed{2, 1, 3};
103+
std::mt19937 rng(seed);
104+
105+
std::uniform_int_distribution pos(0, 4000);
106+
std::uniform_int_distribution size(1, maxSize);
107+
108+
std::vector<SkIRect> rects;
109+
for (int i = 0; i < 2000; ++i) {
110+
SkIRect rect = SkIRect::MakeXYWH(pos(rng), pos(rng), size(rng), size(rng));
111+
rects.push_back(rect);
112+
}
113+
114+
Region region(rects);
115+
116+
while (state.KeepRunning()) {
96117
auto vec2 = region.getRects();
97118
}
98119
}
@@ -195,6 +216,14 @@ static void BM_SkRegion_AddRects(benchmark::State& state, int maxSize) {
195216
RunAddRectsBenchmark<SkRegionAdapter>(state, maxSize);
196217
}
197218

219+
static void BM_DlRegion_GetRects(benchmark::State& state, int maxSize) {
220+
RunGetRectsBenchmark<DlRegionAdapter>(state, maxSize);
221+
}
222+
223+
static void BM_SkRegion_GetRects(benchmark::State& state, int maxSize) {
224+
RunGetRectsBenchmark<SkRegionAdapter>(state, maxSize);
225+
}
226+
198227
static void BM_DlRegion_MakeUnion(benchmark::State& state, int maxSize) {
199228
RunUnionRegionBenchmark<DlRegionAdapter>(state, maxSize);
200229
}
@@ -289,4 +318,21 @@ BENCHMARK_CAPTURE(BM_DlRegion_AddRects, Large, 1500)
289318
BENCHMARK_CAPTURE(BM_SkRegion_AddRects, Large, 1500)
290319
->Unit(benchmark::kMicrosecond);
291320

321+
BENCHMARK_CAPTURE(BM_DlRegion_GetRects, Tiny, 30)
322+
->Unit(benchmark::kMicrosecond);
323+
BENCHMARK_CAPTURE(BM_SkRegion_GetRects, Tiny, 30)
324+
->Unit(benchmark::kMicrosecond);
325+
BENCHMARK_CAPTURE(BM_DlRegion_GetRects, Small, 100)
326+
->Unit(benchmark::kMicrosecond);
327+
BENCHMARK_CAPTURE(BM_SkRegion_GetRects, Small, 100)
328+
->Unit(benchmark::kMicrosecond);
329+
BENCHMARK_CAPTURE(BM_DlRegion_GetRects, Medium, 400)
330+
->Unit(benchmark::kMicrosecond);
331+
BENCHMARK_CAPTURE(BM_SkRegion_GetRects, Medium, 400)
332+
->Unit(benchmark::kMicrosecond);
333+
BENCHMARK_CAPTURE(BM_DlRegion_GetRects, Large, 1500)
334+
->Unit(benchmark::kMicrosecond);
335+
BENCHMARK_CAPTURE(BM_SkRegion_GetRects, Large, 1500)
336+
->Unit(benchmark::kMicrosecond);
337+
292338
} // namespace flutter

0 commit comments

Comments
 (0)