Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Unified Diff: bench/SkGlyphCacheBench.cpp

Issue 1348883002: Font cache stress test. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make a nanobench Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/SkGlyphCacheBench.cpp
diff --git a/bench/SkGlyphCacheBench.cpp b/bench/SkGlyphCacheBench.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8172b05ac82f5de39f27c68b286fbc5dbf69aa1f
--- /dev/null
+++ b/bench/SkGlyphCacheBench.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#include "SkGlyphCache.h"
+
+#include "Benchmark.h"
+#include "SkCanvas.h"
+#include "SkGlyphCache_Globals.h"
+#include "SkGraphics.h"
+#include "SkTaskGroup.h"
+#include "SkTypeface.h"
+#include "sk_tool_utils.h"
+
+
+class SkGlyphCacheBasic : public Benchmark {
+ const char* onGetName() override {
+ return "SkGlyphCacheBasic";
+ }
+ void onDraw(const int loops, SkCanvas* canvas) override {
+ SkGraphics::SetFontCacheLimit(256 * 1024);
+ SkTypeface* typeface = sk_tool_utils::create_portable_typeface("serif",
+ SkTypeface::kItalic);
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setSubpixelText(true);
+ paint.setTypeface(typeface);
+
+ for (int work = 0; work < loops; work++) {
+ for (int i = 8; i < 128; i++) {
+ paint.setTextSize(i);
+ SkAutoGlyphCacheNoGamma autoCache(paint, nullptr, nullptr);
+ SkGlyphCache* cache = autoCache.getCache();
+ uint16_t glyphId = cache->unicharToGlyph('e');
+ const SkGlyph& g = cache->getGlyphIDMetrics(glyphId);
+ cache->findImage(g);
+ }
+ }
+ }
+private:
+ typedef Benchmark INHERITED;
+};
+
+class SkGlyphCacheStressTest : public Benchmark {
mtklein 2015/09/16 22:33:51 For non-rendering benchmarks like these, typically
herb_g 2015/09/17 15:33:19 Done.
+ const char* onGetName() override {
+ return "SkGlyphCacheStressTest";
+ }
+ void onDraw(const int loops, SkCanvas* canvas) override {
+ SkGraphics::SetFontCacheLimit(256 * 1024);
mtklein 2015/09/16 22:33:51 Might be nice to set this back to whatever it star
herb_g 2015/09/17 15:33:19 Done.
+ SkTypeface* typefaces[] =
+ {sk_tool_utils::create_portable_typeface("serif", SkTypeface::kItalic),
+ sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kItalic)};
+
+ for (int work = 0; work < loops; work++) {
+ sk_parallel_for(16, [&](int threadIndex) {
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setSubpixelText(true);
+ paint.setTypeface(typefaces[threadIndex % 2]);
+ for (int size = 8; size < 128; size++) {
+ paint.setTextSize(size);
+ SkAutoGlyphCacheNoGamma autoCache(paint, nullptr, nullptr);
+ SkGlyphCache* cache = autoCache.getCache();
+ for (int c = ' '; c < 'z'; c++) {
+ uint16_t glyphId = cache->unicharToGlyph(c);
+ const SkGlyph& g = cache->getGlyphIDMetrics(glyphId);
+ cache->findImage(g);
+ }
+ }
+ });
+ }
+ }
+private:
+ typedef Benchmark INHERITED;
+};
+
+DEF_BENCH(return new SkGlyphCacheBasic; )
+DEF_BENCH(return new SkGlyphCacheStressTest; )
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698