Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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"

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 186 of file skparagraph_benchmarks.cc.

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

◆ BENCHMARK_DEFINE_F() [2/2]

BENCHMARK_DEFINE_F ( SkParagraphFixture  ,
TextBigO   
)

Definition at line 159 of file skparagraph_benchmarks.cc.

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

◆ BENCHMARK_F() [1/8]

BENCHMARK_F ( SkParagraphFixture  ,
JustifyLayout   
)

Definition at line 104 of file skparagraph_benchmarks.cc.

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

◆ BENCHMARK_F() [2/8]

BENCHMARK_F ( SkParagraphFixture  ,
LongLayout   
)

Definition at line 69 of file skparagraph_benchmarks.cc.

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

◆ BENCHMARK_F() [3/8]

BENCHMARK_F ( SkParagraphFixture  ,
ManyStylesLayout   
)

Definition at line 140 of file skparagraph_benchmarks.cc.

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

◆ BENCHMARK_F() [4/8]

BENCHMARK_F ( SkParagraphFixture  ,
PaintDecoration   
)

Definition at line 269 of file skparagraph_benchmarks.cc.

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

◆ BENCHMARK_F() [5/8]

BENCHMARK_F ( SkParagraphFixture  ,
PaintLarge   
)

Definition at line 231 of file skparagraph_benchmarks.cc.

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

◆ BENCHMARK_F() [6/8]

BENCHMARK_F ( SkParagraphFixture  ,
PaintSimple   
)

Definition at line 211 of file skparagraph_benchmarks.cc.

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

◆ BENCHMARK_F() [7/8]

BENCHMARK_F ( SkParagraphFixture  ,
ShortLayout   
)

Definition at line 51 of file skparagraph_benchmarks.cc.

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

◆ BENCHMARK_F() [8/8]

BENCHMARK_F ( SkParagraphFixture  ,
SimpleBuilder   
)

Definition at line 303 of file skparagraph_benchmarks.cc.

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

◆ RangeMultiplier()

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