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

Unified Diff: bench/ImageCacheBench.cpp

Issue 20005003: add scaledimagecache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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 | gyp/bench.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/ImageCacheBench.cpp
diff --git a/bench/ImageCacheBench.cpp b/bench/ImageCacheBench.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3a22a47826b767a0a9b2338ad95ccc1ef4993fdb
--- /dev/null
+++ b/bench/ImageCacheBench.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBenchmark.h"
+#include "SkScaledImageCache.h"
+
+class ImageCacheBench : public SkBenchmark {
+ SkScaledImageCache fCache;
+ SkBitmap fBM;
+
+ enum {
+ N = SkBENCHLOOP(1000),
+ DIM = 1,
+ CACHE_COUNT = 500
+ };
+public:
+ ImageCacheBench(void* param) : INHERITED(param) , fCache(CACHE_COUNT * 100) {
+ fBM.setConfig(SkBitmap::kARGB_8888_Config, DIM, DIM);
+ fBM.allocPixels();
+ }
+
+ void populateCache() {
+ SkScalar scale = 1;
+ for (int i = 0; i < CACHE_COUNT; ++i) {
+ SkBitmap tmp;
+ tmp.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
+ tmp.allocPixels();
+ fCache.unlock(fCache.addAndLock(fBM, scale, scale, tmp));
+ scale += 1;
+ }
+ }
+
+protected:
+ virtual const char* onGetName() SK_OVERRIDE {
+ return "imagecache";
+ }
+
+ virtual void onDraw(SkCanvas*) SK_OVERRIDE {
+ if (fCache.getBytesUsed() == 0) {
+ this->populateCache();
+ }
+
+ SkBitmap tmp;
+ // search for a miss (-1 scale)
+ for (int i = 0; i < N; ++i) {
+ (void)fCache.findAndLock(fBM, -1, -1, &tmp);
+ }
+ }
+
+private:
+ typedef SkBenchmark INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+DEF_BENCH( return new ImageCacheBench(p); )
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698