Skip to content

Commit

Permalink
More feedback I missed
Browse files Browse the repository at this point in the history
  • Loading branch information
aballway committed Jan 31, 2017
1 parent d3fc1b5 commit 44738b0
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/build.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Starboard", "Starboard", "{ADFDC5D9-3048-4E53-A9B7-41731D7AD8CF}"
EndProject
Expand Down
71 changes: 70 additions & 1 deletion tests/UnitTests/Benchmark/TextBenchmarkTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,76 @@
@"proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
static constexpr UniChar sc_chars[4] = { 'T', 'E', 'S', 'T' };

class CTFramesetterCreateFrameTest : public ::testing::BenchmarkTestBase {
woc::AutoCF<CTFramesetterRef> m_framesetter;
woc::AutoCF<CGPathRef> m_path;

public:
CTFramesetterCreateFrameTest(CGSize size) {
CTParagraphStyleSetting setting;
CTTextAlignment alignment = kCTCenterTextAlignment;
setting.spec = kCTParagraphStyleSpecifierAlignment;
setting.valueSize = sizeof(CTTextAlignment);
setting.value = &alignment;
auto paragraphStyle = woc::MakeAutoCF<CTParagraphStyleRef>(CTParagraphStyleCreate(&setting, std::extent<decltype(setting)>::value));
UIFont* font = [UIFont systemFontOfSize:24];

CFStringRef keys[2] = { kCTFontAttributeName, kCTParagraphStyleAttributeName };
CFTypeRef values[2] = { font, paragraphStyle };
auto dict = woc::MakeAutoCF<CFDictionaryRef>(CFDictionaryCreate(nullptr,
(const void**)keys,
(const void**)values,
std::extent<decltype(keys)>::value,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks));

auto attrString = woc::MakeAutoCF<CFAttributedStringRef>(CFAttributedStringCreate(nullptr, (CFStringRef)sc_frameText, dict));
m_framesetter = woc::MakeAutoCF<CTFramesetterRef>(CTFramesetterCreateWithAttributedString(attrString));
m_path = woc::MakeAutoCF<CGMutablePathRef>(CGPathCreateMutable());
CGPathAddRect(m_path, nullptr, CGRect{ CGPointZero, size });
}

inline void Run() {
auto frame = woc::MakeAutoCF<CTFrameRef>(CTFramesetterCreateFrame(m_framesetter, CFRange{ 0, 0 }, m_path, nullptr));
}

size_t GetRunCount() const {
return 100;
}
};

static constexpr CGSize c_sizes[] = { { 0, 0 }, { 0, 512 }, { 256, 0 }, { 256, 512 } };
BENCHMARK_REGISTER_TEST_P(CoreText, CTFramesetterCreateFrameTest, ::testing::ValuesIn(c_sizes), CGSize);

class CTLineCreateTest : public ::testing::BenchmarkTestBase {
woc::AutoCF<CFAttributedStringRef> m_attrString;

public:
CTLineCreateTest() {
UIFont* font = [UIFont systemFontOfSize:24];

CFStringRef keys[1] = { kCTFontAttributeName };
CFTypeRef values[1] = { font };
auto dict = woc::MakeAutoCF<CFDictionaryRef>(CFDictionaryCreate(nullptr,
(const void**)keys,
(const void**)values,
std::extent<decltype(keys)>::value,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks));
m_attrString = woc::MakeAutoCF<CFAttributedStringRef>(CFAttributedStringCreate(nullptr, (CFStringRef)sc_frameText, dict));
}

inline void Run() {
auto line = woc::MakeAutoCF<CTLineRef>(CTLineCreateWithAttributedString(m_attrString));
}

size_t GetRunCount() const {
return 100;
}
};

TEST_BENCHMARK_F(CoreText, CTLineCreateTest);

class TextBenchmarkBase : public ::testing::BenchmarkTestBase {
public:
TextBenchmarkBase() {
Expand Down Expand Up @@ -444,7 +514,6 @@ size_t GetRunCount() const {
CGSize m_rectSize;
};

static constexpr CGSize c_sizes[] = { { 0, 0 }, { 0, 512 }, { 256, 0 }, { 256, 512 } };
BENCHMARK_REGISTER_TEST_P(NSString, DrawInRect, ::testing::ValuesIn(c_sizes), CGSize);

class SizeWithFont : public NSString_UIKitBase {
Expand Down

0 comments on commit 44738b0

Please sign in to comment.