Flutter Engine
The Flutter Engine
Classes | Functions
skparagraph_benchmarks.cc File Reference
#include <sstream>
#include "flutter/fml/command_line.h"
#include "flutter/fml/logging.h"
#include "flutter/third_party/txt/tests/txt_test_utils.h"
#include "third_party/benchmark/include/benchmark/benchmark.h"
#include "third_party/icu/source/common/unicode/unistr.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/modules/skparagraph/include/Paragraph.h"
#include "third_party/skia/modules/skparagraph/include/ParagraphBuilder.h"
#include "third_party/skia/modules/skparagraph/include/TypefaceFontProvider.h"
#include "third_party/skia/modules/skparagraph/utils/TestFontCollection.h"
#include "third_party/skia/modules/skunicode/include/SkUnicode_icu.h"

Go to the source code of this file.

Classes

class  SkParagraphFixture
 

Functions

 BENCHMARK_F (SkParagraphFixture, ShortLayout)(benchmark
 
 BENCHMARK_F (SkParagraphFixture, LongLayout)(benchmark
 
 BENCHMARK_F (SkParagraphFixture, JustifyLayout)(benchmark
 
 BENCHMARK_F (SkParagraphFixture, ManyStylesLayout)(benchmark
 
 BENCHMARK_DEFINE_F (SkParagraphFixture, TextBigO)(benchmark
 
 RangeMultiplier (4) -> Range(1<< 6, 1<< 14) ->Complexity(benchmark::oN)
 
 BENCHMARK_DEFINE_F (SkParagraphFixture, StylesBigO)(benchmark
 
 BENCHMARK_F (SkParagraphFixture, PaintSimple)(benchmark
 
 BENCHMARK_F (SkParagraphFixture, PaintLarge)(benchmark
 
 BENCHMARK_F (SkParagraphFixture, PaintDecoration)(benchmark
 
 BENCHMARK_F (SkParagraphFixture, SimpleBuilder)(benchmark
 

Function Documentation

◆ BENCHMARK_DEFINE_F() [1/2]

BENCHMARK_DEFINE_F ( SkParagraphFixture  ,
StylesBigO   
)

Definition at line 187 of file skparagraph_benchmarks.cc.

187 {
188 const char* text = "vry shrt ";
189 sktxt::ParagraphStyle paragraph_style;
190 sktxt::TextStyle text_style;
191 text_style.setFontFamilies({SkString("Roboto")});
192 text_style.setColor(SK_ColorBLACK);
194 paragraph_style,
195 sk_make_sp<sktxt::TestFontCollection>(txt::GetFontDir()),
197 for (int i = 0; i < 1000; ++i) {
198 builder->pushStyle(text_style);
199 builder->addText(text);
200 }
201 auto paragraph = builder->Build();
202 while (state.KeepRunning()) {
203 paragraph->markDirty();
204 paragraph->layout(300);
205 }
206 state.SetComplexityN(state.range(0));
207}
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
static std::unique_ptr< ParagraphBuilder > make(const ParagraphStyle &style, sk_sp< FontCollection > fontCollection, sk_sp< SkUnicode > unicode)
void setFontFamilies(std::vector< SkString > families)
Definition: TextStyle.h:253
void setColor(SkColor color)
Definition: TextStyle.h:166
AtkStateType state
std::u16string text
SKUNICODE_API sk_sp< SkUnicode > Make()
const std::string & GetFontDir()

◆ BENCHMARK_DEFINE_F() [2/2]

BENCHMARK_DEFINE_F ( SkParagraphFixture  ,
TextBigO   
)

Definition at line 160 of file skparagraph_benchmarks.cc.

160 {
161 std::vector<uint16_t> text;
162 for (uint16_t i = 0; i < state.range(0); ++i) {
163 text.push_back(i % 5 == 0 ? ' ' : i);
164 }
165 std::u16string u16_text(text.data(), text.data() + text.size());
166 sktxt::ParagraphStyle paragraph_style;
167 sktxt::TextStyle text_style;
168 text_style.setFontFamilies({SkString("Roboto")});
169 text_style.setColor(SK_ColorBLACK);
170 auto builder =
171 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make());
172 builder->pushStyle(text_style);
173 builder->addText(u16_text);
174 builder->pop();
175 auto paragraph = builder->Build();
176 while (state.KeepRunning()) {
177 paragraph->markDirty();
178 paragraph->layout(300);
179 }
180 state.SetComplexityN(state.range(0));
181}

◆ BENCHMARK_F() [1/8]

BENCHMARK_F ( SkParagraphFixture  ,
JustifyLayout   
)

Definition at line 105 of file skparagraph_benchmarks.cc.

105 {
106 const char* text =
107 "This is a very long sentence to test if the text will properly wrap "
108 "around and go to the next line. Sometimes, short sentence. Longer "
109 "sentences are okay too because they are necessary. Very short. "
110 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
111 "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
112 "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
113 "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
114 "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
115 "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
116 "mollit anim id est laborum. "
117 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
118 "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
119 "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
120 "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
121 "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
122 "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
123 "mollit anim id est laborum.";
124 sktxt::ParagraphStyle paragraph_style;
125 paragraph_style.setTextAlign(sktxt::TextAlign::kJustify);
126 sktxt::TextStyle text_style;
127 text_style.setFontFamilies({SkString("Roboto")});
128 text_style.setColor(SK_ColorBLACK);
129 auto builder =
130 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make());
131 builder->pushStyle(text_style);
132 builder->addText(text);
133 builder->pop();
134 auto paragraph = builder->Build();
135 while (state.KeepRunning()) {
136 paragraph->markDirty();
137 paragraph->layout(300);
138 }
139}
void setTextAlign(TextAlign align)

◆ BENCHMARK_F() [2/8]

BENCHMARK_F ( SkParagraphFixture  ,
LongLayout   
)

Definition at line 70 of file skparagraph_benchmarks.cc.

70 {
71 const char* text =
72 "This is a very long sentence to test if the text will properly wrap "
73 "around and go to the next line. Sometimes, short sentence. Longer "
74 "sentences are okay too because they are necessary. Very short. "
75 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
76 "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
77 "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
78 "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
79 "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
80 "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
81 "mollit anim id est laborum. "
82 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
83 "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
84 "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
85 "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
86 "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
87 "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
88 "mollit anim id est laborum.";
89 sktxt::ParagraphStyle paragraph_style;
90 sktxt::TextStyle text_style;
91 text_style.setFontFamilies({SkString("Roboto")});
92 text_style.setColor(SK_ColorBLACK);
93 auto builder =
94 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make());
95 builder->pushStyle(text_style);
96 builder->addText(text);
97 builder->pop();
98 auto paragraph = builder->Build();
99 while (state.KeepRunning()) {
100 paragraph->markDirty();
101 paragraph->layout(300);
102 }
103}

◆ BENCHMARK_F() [3/8]

BENCHMARK_F ( SkParagraphFixture  ,
ManyStylesLayout   
)

Definition at line 141 of file skparagraph_benchmarks.cc.

141 {
142 const char* text = "-";
143 sktxt::ParagraphStyle paragraph_style;
144 sktxt::TextStyle text_style;
145 text_style.setFontFamilies({SkString("Roboto")});
146 text_style.setColor(SK_ColorBLACK);
147 auto builder =
148 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make());
149 for (int i = 0; i < 1000; ++i) {
150 builder->pushStyle(text_style);
151 builder->addText(text);
152 }
153 auto paragraph = builder->Build();
154 while (state.KeepRunning()) {
155 paragraph->markDirty();
156 paragraph->layout(300);
157 }
158}

◆ BENCHMARK_F() [4/8]

BENCHMARK_F ( SkParagraphFixture  ,
PaintDecoration   
)

Definition at line 271 of file skparagraph_benchmarks.cc.

271 {
272 const char* text =
273 "Hello world! This is a simple sentence to test drawing. Hello world! "
274 "This is a simple sentence to test drawing.";
275 sktxt::ParagraphStyle paragraph_style;
276 sktxt::TextStyle text_style;
277 text_style.setFontFamilies({SkString("Roboto")});
278 text_style.setColor(SK_ColorBLACK);
279 text_style.setDecoration(static_cast<sktxt::TextDecoration>(
282 auto builder =
283 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make());
285 builder->pushStyle(text_style);
286 builder->addText(text);
287
289 builder->pushStyle(text_style);
290 builder->addText(text);
291
293 builder->pushStyle(text_style);
294 builder->addText(text);
295
296 auto paragraph = builder->Build();
297 paragraph->layout(300);
298 int offset = 0;
299 while (state.KeepRunning()) {
300 paragraph->paint(canvas_.get(), offset % 700, 10);
301 offset++;
302 }
303}
void setDecorationStyle(TextDecorationStyle style)
Definition: TextStyle.h:222
void setDecoration(TextDecoration decoration)
Definition: TextStyle.h:220
SeparatedVector2 offset

◆ BENCHMARK_F() [5/8]

BENCHMARK_F ( SkParagraphFixture  ,
PaintLarge   
)

Definition at line 233 of file skparagraph_benchmarks.cc.

233 {
234 const char* text =
235 "Hello world! This is a simple sentence to test drawing. Hello world! "
236 "This is a simple sentence to test drawing. Hello world! This is a "
237 "simple sentence to test drawing.Hello world! This is a simple sentence "
238 "to test drawing. Hello world! "
239 "This is a simple sentence to test drawing. Hello world! This is a "
240 "simple sentence to test drawing.Hello world! This is a simple sentence "
241 "to test drawing. Hello world! "
242 "This is a simple sentence to test drawing. Hello world! This is a "
243 "simple sentence to test drawing.Hello world! This is a simple sentence "
244 "to test drawing. Hello world! "
245 "This is a simple sentence to test drawing. Hello world! This is a "
246 "simple sentence to test drawing.Hello world! This is a simple sentence "
247 "to test drawing. Hello world! "
248 "This is a simple sentence to test drawing. Hello world! This is a "
249 "simple sentence to test drawing.Hello world! This is a simple sentence "
250 "to test drawing. Hello world! "
251 "This is a simple sentence to test drawing. Hello world! This is a "
252 "simple sentence to test drawing.";
253 sktxt::ParagraphStyle paragraph_style;
254 sktxt::TextStyle text_style;
255 text_style.setFontFamilies({SkString("Roboto")});
256 text_style.setColor(SK_ColorBLACK);
257 auto builder =
258 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make());
259 builder->pushStyle(text_style);
260 builder->addText(text);
261 builder->pop();
262 auto paragraph = builder->Build();
263 paragraph->layout(300);
264 int offset = 0;
265 while (state.KeepRunning()) {
266 paragraph->paint(canvas_.get(), offset % 700, 10);
267 offset++;
268 }
269}

◆ BENCHMARK_F() [6/8]

BENCHMARK_F ( SkParagraphFixture  ,
PaintSimple   
)

Definition at line 213 of file skparagraph_benchmarks.cc.

213 {
214 const char* text = "This is a simple sentence to test drawing.";
215 sktxt::ParagraphStyle paragraph_style;
216 sktxt::TextStyle text_style;
217 text_style.setFontFamilies({SkString("Roboto")});
218 text_style.setColor(SK_ColorBLACK);
219 auto builder =
220 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make());
221 builder->pushStyle(text_style);
222 builder->addText(text);
223 builder->pop();
224 auto paragraph = builder->Build();
225 paragraph->layout(300);
226 int offset = 0;
227 while (state.KeepRunning()) {
228 paragraph->paint(canvas_.get(), offset % 700, 10);
229 offset++;
230 }
231}

◆ BENCHMARK_F() [7/8]

BENCHMARK_F ( SkParagraphFixture  ,
ShortLayout   
)

Definition at line 52 of file skparagraph_benchmarks.cc.

52 {
53 const char* text = "Hello World";
54 sktxt::ParagraphStyle paragraph_style;
55 sktxt::TextStyle text_style;
56 text_style.setFontFamilies({SkString("Roboto")});
57 text_style.setColor(SK_ColorBLACK);
58 auto builder =
59 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make());
60 builder->pushStyle(text_style);
61 builder->addText(text);
62 builder->pop();
63 auto paragraph = builder->Build();
64 while (state.KeepRunning()) {
65 paragraph->markDirty();
66 paragraph->layout(300);
67 }
68}

◆ BENCHMARK_F() [8/8]

BENCHMARK_F ( SkParagraphFixture  ,
SimpleBuilder   
)

Definition at line 305 of file skparagraph_benchmarks.cc.

305 {
306 const char* text = "Hello World";
307 sktxt::ParagraphStyle paragraph_style;
308 sktxt::TextStyle text_style;
309 text_style.setFontFamilies({SkString("Roboto")});
310 text_style.setColor(SK_ColorBLACK);
311 while (state.KeepRunning()) {
312 auto builder =
313 sktxt::ParagraphBuilder::make(paragraph_style, font_collection_, SkUnicodes::ICU::Make());
314 builder->pushStyle(text_style);
315 builder->addText(text);
316 builder->pop();
317 auto paragraph = builder->Build();
318 }
319}

◆ RangeMultiplier()

RangeMultiplier ( ) -> Range(1<< 6, 1<< 14) ->Complexity(benchmark::oN)