Fix the libTXT benchmarking target for API updates and compile on Mac. (flutter/engine#4049)

This commit is contained in:
Chinmay Garde
2017-09-01 12:27:35 -07:00
committed by GitHub
parent 7d184eb710
commit db6a6c8809
7 changed files with 51 additions and 111 deletions

View File

@@ -43,12 +43,10 @@ group("flutter") {
"//flutter/fml:fml_unittests",
"//flutter/sky/engine/wtf:wtf_unittests",
"//flutter/synchronization:synchronization_unittests",
"//flutter/third_party/txt:txt_benchmarks",
"//flutter/third_party/txt:txt_unittests",
"//garnet/public/lib/ftl:ftl_unittests",
]
if (is_linux) {
deps += [ "//flutter/third_party/txt:txt_benchmarks" ]
}
}
}

View File

@@ -167,7 +167,6 @@ executable("txt_benchmarks") {
testonly = true
sources = [
"benchmarks/font_collection_benchmarks.cc",
"benchmarks/paint_record_benchmarks.cc",
"benchmarks/paragraph_benchmarks.cc",
"benchmarks/paragraph_builder_benchmarks.cc",

View File

@@ -1,68 +0,0 @@
/*
* Copyright 2017 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "third_party/benchmark/include/benchmark/benchmark_api.h"
#include "lib/ftl/command_line.h"
#include "lib/ftl/logging.h"
#include "third_party/skia/include/ports/SkFontMgr.h"
#include "third_party/skia/include/ports/SkFontMgr_directory.h"
#include "txt/font_collection.h"
#include "utils.h"
namespace txt {
// Include this fake bench first because the first benchmark produces
// inconsistent times.
static void BM_FAKE_BENCHMARK(benchmark::State& state) {
while (state.KeepRunning()) {
continue;
}
}
BENCHMARK(BM_FAKE_BENCHMARK);
static void BM_FontCollectionCustomInit(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(
FontCollection::GetFontCollection(txt::GetFontDir()));
}
}
BENCHMARK(BM_FontCollectionCustomInit);
static void BM_FontCollectionInit(benchmark::State& state) {
while (state.KeepRunning()) {
benchmark::DoNotOptimize(FontCollection::GetFontCollection());
}
}
BENCHMARK(BM_FontCollectionInit);
static void BM_FontCollectionSkFontMgr(benchmark::State& state) {
while (state.KeepRunning()) {
auto mgr = SkFontMgr_New_Custom_Directory(txt::GetFontDir().c_str());
}
}
BENCHMARK(BM_FontCollectionSkFontMgr);
static void BM_FontCollectionGetMinikinFontCollectionForFamily(
benchmark::State& state) {
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
while (state.KeepRunning()) {
font_collection.GetMinikinFontCollectionForFamily("Roboto");
}
}
BENCHMARK(BM_FontCollectionGetMinikinFontCollectionForFamily);
} // namespace txt

View File

@@ -45,8 +45,7 @@ static void BM_ParagraphShortLayout(benchmark::State& state) {
txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
builder.PushStyle(text_style);
builder.AddText(u16_text);
@@ -86,8 +85,8 @@ static void BM_ParagraphLongLayout(benchmark::State& state) {
txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
builder.PushStyle(text_style);
builder.AddText(u16_text);
@@ -128,8 +127,8 @@ static void BM_ParagraphJustifyLayout(benchmark::State& state) {
txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
builder.PushStyle(text_style);
builder.AddText(u16_text);
@@ -152,8 +151,7 @@ static void BM_ParagraphManyStylesLayout(benchmark::State& state) {
txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
for (int i = 0; i < 1000; ++i) {
builder.PushStyle(text_style);
builder.AddText(u16_text);
@@ -177,9 +175,8 @@ static void BM_ParagraphTextBigO(benchmark::State& state) {
txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
builder.PushStyle(text_style);
builder.AddText(u16_text);
@@ -206,8 +203,8 @@ static void BM_ParagraphStylesBigO(benchmark::State& state) {
txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
for (int i = 0; i < state.range(0); ++i) {
builder.PushStyle(text_style);
@@ -235,8 +232,7 @@ static void BM_ParagraphPaintSimple(benchmark::State& state) {
txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
builder.PushStyle(text_style);
builder.AddText(u16_text);
auto paragraph = builder.Build();
@@ -282,8 +278,7 @@ static void BM_ParagraphPaintLarge(benchmark::State& state) {
txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
builder.PushStyle(text_style);
builder.AddText(u16_text);
auto paragraph = builder.Build();
@@ -316,8 +311,7 @@ static void BM_ParagraphPaintDecoration(benchmark::State& state) {
text_style.decoration_style = TextDecorationStyle(kSolid);
text_style.color = SK_ColorBLACK;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
builder.PushStyle(text_style);
builder.AddText(u16_text);
@@ -367,9 +361,8 @@ static void BM_ParagraphMinikinDoLayout(benchmark::State& state) {
paint.letterSpacing = text_style.letter_spacing;
paint.wordSpacing = text_style.word_spacing;
auto collection =
FontCollection::GetFontCollection(txt::GetFontDir())
.GetMinikinFontCollectionForFamily(text_style.font_family);
auto collection = GetTestFontCollection()->GetMinikinFontCollectionForFamily(
text_style.font_family);
while (state.KeepRunning()) {
minikin::Layout layout;
@@ -398,7 +391,7 @@ static void BM_ParagraphMinikinAddStyleRun(benchmark::State& state) {
paint.letterSpacing = text_style.letter_spacing;
paint.wordSpacing = text_style.word_spacing;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
auto font_collection = GetTestFontCollection();
minikin::LineBreaker breaker;
breaker.setLocale(icu::Locale(), nullptr);
@@ -409,7 +402,7 @@ static void BM_ParagraphMinikinAddStyleRun(benchmark::State& state) {
while (state.KeepRunning()) {
for (int i = 0; i < 20; ++i) {
breaker.addStyleRun(
&paint, font_collection.GetMinikinFontCollectionForFamily("Roboto"),
&paint, font_collection->GetMinikinFontCollectionForFamily("Roboto"),
font, state.range(0) / 20 * i, state.range(0) / 20 * (i + 1), false,
0);
}

View File

@@ -31,8 +31,9 @@ namespace txt {
static void BM_ParagraphBuilderConstruction(benchmark::State& state) {
txt::ParagraphStyle paragraph_style;
auto font_collection = GetTestFontCollection();
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style);
txt::ParagraphBuilder builder(paragraph_style, font_collection);
}
}
BENCHMARK(BM_ParagraphBuilderConstruction);
@@ -42,9 +43,9 @@ static void BM_ParagraphBuilderPushStyle(benchmark::State& state) {
txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
auto font_collection = GetTestFontCollection();
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, font_collection);
builder.PushStyle(text_style);
}
}
@@ -52,7 +53,7 @@ BENCHMARK(BM_ParagraphBuilderPushStyle);
static void BM_ParagraphBuilderPushPop(benchmark::State& state) {
txt::ParagraphStyle paragraph_style;
txt::ParagraphBuilder builder(paragraph_style);
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
@@ -66,10 +67,12 @@ BENCHMARK(BM_ParagraphBuilderPushPop);
static void BM_ParagraphBuilderAddTextString(benchmark::State& state) {
std::string text = "Hello World";
auto font_collection = GetTestFontCollection();
txt::ParagraphStyle paragraph_style;
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style);
txt::ParagraphBuilder builder(paragraph_style, font_collection);
builder.AddText(text);
}
}
@@ -79,9 +82,9 @@ static void BM_ParagraphBuilderAddTextChar(benchmark::State& state) {
const char* text = "Hello World";
txt::ParagraphStyle paragraph_style;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
auto font_collection = GetTestFontCollection();
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, font_collection);
builder.AddText(text);
}
}
@@ -94,9 +97,9 @@ static void BM_ParagraphBuilderAddTextU16stringShort(benchmark::State& state) {
icu_text.getBuffer() + icu_text.length());
txt::ParagraphStyle paragraph_style;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
auto font_collection = GetTestFontCollection();
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, font_collection);
builder.AddText(u16_text);
}
}
@@ -125,10 +128,12 @@ static void BM_ParagraphBuilderAddTextU16stringLong(benchmark::State& state) {
std::u16string u16_text(icu_text.getBuffer(),
icu_text.getBuffer() + icu_text.length());
auto font_collection = GetTestFontCollection();
txt::ParagraphStyle paragraph_style;
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style);
txt::ParagraphBuilder builder(paragraph_style, font_collection);
builder.AddText(u16_text);
}
}
@@ -145,9 +150,9 @@ static void BM_ParagraphBuilderShortParagraphConstruct(
txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
auto font_collection = GetTestFontCollection();
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, font_collection);
builder.PushStyle(text_style);
builder.AddText(u16_text);
builder.Pop();
@@ -183,9 +188,9 @@ static void BM_ParagraphBuilderLongParagraphConstruct(benchmark::State& state) {
txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
auto font_collection = GetTestFontCollection();
while (state.KeepRunning()) {
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::ParagraphBuilder builder(paragraph_style, font_collection);
builder.PushStyle(text_style);
builder.AddText(u16_text);
builder.Pop();

View File

@@ -17,6 +17,8 @@
#include <string>
#include "lib/ftl/command_line.h"
#include "txt/directory_asset_data_provider.h"
#include "txt/font_collection.h"
#include "utils.h"
namespace txt {
@@ -24,7 +26,7 @@ namespace txt {
static std::string gFontDir;
static ftl::CommandLine gCommandLine;
const std::string GetFontDir() {
const std::string& GetFontDir() {
return gFontDir;
}
@@ -40,4 +42,11 @@ void SetCommandLine(ftl::CommandLine cmd) {
gCommandLine = std::move(cmd);
}
std::shared_ptr<FontCollection> GetTestFontCollection() {
auto collection = std::make_shared<FontCollection>();
collection->PushBack(sk_make_sp<AssetFontManager>(
std::make_unique<DirectoryAssetDataProvider>(GetFontDir())));
return collection;
}
} // namespace txt

View File

@@ -20,7 +20,9 @@
namespace txt {
const std::string GetFontDir();
class FontCollection;
const std::string& GetFontDir();
void SetFontDir(const std::string& dir);
@@ -28,4 +30,6 @@ const ftl::CommandLine& GetCommandLineForProcess();
void SetCommandLine(ftl::CommandLine cmd);
std::shared_ptr<FontCollection> GetTestFontCollection();
} // namespace txt