Flutter Engine
 
Loading...
Searching...
No Matches
skparagraph_benchmarks.cc File Reference
#include <sstream>
#include "flutter/fml/command_line.h"
#include "flutter/fml/logging.h"
#include "flutter/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 176 of file skparagraph_benchmarks.cc.

176 {
177 const char* text = "vry shrt ";
178 sktxt::ParagraphStyle paragraph_style;
179 sktxt::TextStyle text_style;
180 text_style.setFontFamilies({SkString("Roboto")});
181 text_style.setColor(SK_ColorBLACK);
182 auto builder = sktxt::ParagraphBuilder::make(
183 paragraph_style, sk_make_sp<sktxt::TestFontCollection>(txt::GetFontDir()),
184 SkUnicodes::ICU::Make());
185 for (int i = 0; i < 1000; ++i) {
186 builder->pushStyle(text_style);
187 builder->addText(text);
188 }
189 auto paragraph = builder->Build();
190 while (state.KeepRunning()) {
191 paragraph->markDirty();
192 paragraph->layout(300);
193 }
194 state.SetComplexityN(state.range(0));
195}
std::u16string text
const std::string & GetFontDir()

References txt::GetFontDir(), i, and text.

◆ BENCHMARK_DEFINE_F() [2/2]

BENCHMARK_DEFINE_F ( SkParagraphFixture  ,
TextBigO   
)

Definition at line 148 of file skparagraph_benchmarks.cc.

148 {
149 std::vector<uint16_t> text;
150 text.reserve(state.range(0));
151 for (uint16_t i = 0; i < state.range(0); ++i) {
152 text.push_back(i % 5 == 0 ? ' ' : i);
153 }
154 std::u16string u16_text(text.data(), text.data() + text.size());
155 sktxt::ParagraphStyle paragraph_style;
156 sktxt::TextStyle text_style;
157 text_style.setFontFamilies({SkString("Roboto")});
158 text_style.setColor(SK_ColorBLACK);
159 auto builder = sktxt::ParagraphBuilder::make(
160 paragraph_style, font_collection_, SkUnicodes::ICU::Make());
161 builder->pushStyle(text_style);
162 builder->addText(u16_text);
163 builder->pop();
164 auto paragraph = builder->Build();
165 while (state.KeepRunning()) {
166 paragraph->markDirty();
167 paragraph->layout(300);
168 }
169 state.SetComplexityN(state.range(0));
170}

References i, and text.

◆ BENCHMARK_F() [1/8]

BENCHMARK_F ( SkParagraphFixture  ,
JustifyLayout   
)

Definition at line 93 of file skparagraph_benchmarks.cc.

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

References text.

◆ BENCHMARK_F() [2/8]

BENCHMARK_F ( SkParagraphFixture  ,
LongLayout   
)

Definition at line 58 of file skparagraph_benchmarks.cc.

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

References text.

◆ BENCHMARK_F() [3/8]

BENCHMARK_F ( SkParagraphFixture  ,
ManyStylesLayout   
)

Definition at line 129 of file skparagraph_benchmarks.cc.

129 {
130 const char* text = "-";
131 sktxt::ParagraphStyle paragraph_style;
132 sktxt::TextStyle text_style;
133 text_style.setFontFamilies({SkString("Roboto")});
134 text_style.setColor(SK_ColorBLACK);
135 auto builder = sktxt::ParagraphBuilder::make(
136 paragraph_style, font_collection_, SkUnicodes::ICU::Make());
137 for (int i = 0; i < 1000; ++i) {
138 builder->pushStyle(text_style);
139 builder->addText(text);
140 }
141 auto paragraph = builder->Build();
142 while (state.KeepRunning()) {
143 paragraph->markDirty();
144 paragraph->layout(300);
145 }
146}

References i, and text.

◆ BENCHMARK_F() [4/8]

BENCHMARK_F ( SkParagraphFixture  ,
PaintDecoration   
)

Definition at line 259 of file skparagraph_benchmarks.cc.

259 {
260 const char* text =
261 "Hello world! This is a simple sentence to test drawing. Hello world! "
262 "This is a simple sentence to test drawing.";
263 sktxt::ParagraphStyle paragraph_style;
264 sktxt::TextStyle text_style;
265 text_style.setFontFamilies({SkString("Roboto")});
266 text_style.setColor(SK_ColorBLACK);
267 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
268 text_style.setDecoration(static_cast<sktxt::TextDecoration>(
269 sktxt::TextDecoration::kLineThrough | sktxt::TextDecoration::kOverline |
270 sktxt::TextDecoration::kUnderline));
271 auto builder = sktxt::ParagraphBuilder::make(
272 paragraph_style, font_collection_, SkUnicodes::ICU::Make());
273 text_style.setDecorationStyle(sktxt::TextDecorationStyle::kSolid);
274 builder->pushStyle(text_style);
275 builder->addText(text);
276
277 text_style.setDecorationStyle(sktxt::TextDecorationStyle::kDotted);
278 builder->pushStyle(text_style);
279 builder->addText(text);
280
281 text_style.setDecorationStyle(sktxt::TextDecorationStyle::kWavy);
282 builder->pushStyle(text_style);
283 builder->addText(text);
284
285 auto paragraph = builder->Build();
286 paragraph->layout(300);
287 int offset = 0;
288 while (state.KeepRunning()) {
289 paragraph->paint(canvas_.get(), offset % 700, 10);
290 offset++;
291 }
292}

References text.

◆ BENCHMARK_F() [5/8]

BENCHMARK_F ( SkParagraphFixture  ,
PaintLarge   
)

Definition at line 221 of file skparagraph_benchmarks.cc.

221 {
222 const char* text =
223 "Hello world! This is a simple sentence to test drawing. Hello world! "
224 "This is a simple sentence to test drawing. Hello world! This is a "
225 "simple sentence to test drawing.Hello world! This is a simple sentence "
226 "to test drawing. Hello world! "
227 "This is a simple sentence to test drawing. Hello world! This is a "
228 "simple sentence to test drawing.Hello world! This is a simple sentence "
229 "to test drawing. Hello world! "
230 "This is a simple sentence to test drawing. Hello world! This is a "
231 "simple sentence to test drawing.Hello world! This is a simple sentence "
232 "to test drawing. Hello world! "
233 "This is a simple sentence to test drawing. Hello world! This is a "
234 "simple sentence to test drawing.Hello world! This is a simple sentence "
235 "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.";
241 sktxt::ParagraphStyle paragraph_style;
242 sktxt::TextStyle text_style;
243 text_style.setFontFamilies({SkString("Roboto")});
244 text_style.setColor(SK_ColorBLACK);
245 auto builder = sktxt::ParagraphBuilder::make(
246 paragraph_style, font_collection_, SkUnicodes::ICU::Make());
247 builder->pushStyle(text_style);
248 builder->addText(text);
249 builder->pop();
250 auto paragraph = builder->Build();
251 paragraph->layout(300);
252 int offset = 0;
253 while (state.KeepRunning()) {
254 paragraph->paint(canvas_.get(), offset % 700, 10);
255 offset++;
256 }
257}

References text.

◆ BENCHMARK_F() [6/8]

BENCHMARK_F ( SkParagraphFixture  ,
PaintSimple   
)

Definition at line 201 of file skparagraph_benchmarks.cc.

201 {
202 const char* text = "This is a simple sentence to test drawing.";
203 sktxt::ParagraphStyle paragraph_style;
204 sktxt::TextStyle text_style;
205 text_style.setFontFamilies({SkString("Roboto")});
206 text_style.setColor(SK_ColorBLACK);
207 auto builder = sktxt::ParagraphBuilder::make(
208 paragraph_style, font_collection_, SkUnicodes::ICU::Make());
209 builder->pushStyle(text_style);
210 builder->addText(text);
211 builder->pop();
212 auto paragraph = builder->Build();
213 paragraph->layout(300);
214 int offset = 0;
215 while (state.KeepRunning()) {
216 paragraph->paint(canvas_.get(), offset % 700, 10);
217 offset++;
218 }
219}

References text.

◆ BENCHMARK_F() [7/8]

BENCHMARK_F ( SkParagraphFixture  ,
ShortLayout   
)

Definition at line 40 of file skparagraph_benchmarks.cc.

40 {
41 const char* text = "Hello World";
42 sktxt::ParagraphStyle paragraph_style;
43 sktxt::TextStyle text_style;
44 text_style.setFontFamilies({SkString("Roboto")});
45 text_style.setColor(SK_ColorBLACK);
46 auto builder = sktxt::ParagraphBuilder::make(
47 paragraph_style, font_collection_, SkUnicodes::ICU::Make());
48 builder->pushStyle(text_style);
49 builder->addText(text);
50 builder->pop();
51 auto paragraph = builder->Build();
52 while (state.KeepRunning()) {
53 paragraph->markDirty();
54 paragraph->layout(300);
55 }
56}

References text.

◆ BENCHMARK_F() [8/8]

BENCHMARK_F ( SkParagraphFixture  ,
SimpleBuilder   
)

Definition at line 294 of file skparagraph_benchmarks.cc.

294 {
295 const char* text = "Hello World";
296 sktxt::ParagraphStyle paragraph_style;
297 sktxt::TextStyle text_style;
298 text_style.setFontFamilies({SkString("Roboto")});
299 text_style.setColor(SK_ColorBLACK);
300 while (state.KeepRunning()) {
301 auto builder = sktxt::ParagraphBuilder::make(
302 paragraph_style, font_collection_, SkUnicodes::ICU::Make());
303 builder->pushStyle(text_style);
304 builder->addText(text);
305 builder->pop();
306 auto paragraph = builder->Build();
307 }
308}

References text.

◆ RangeMultiplier()

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