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

Side by Side Diff: bench/ImageCacheBench.cpp

Issue 569353002: Change SkResourceCache to take a Visitor inside its find(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remember to purge after the add Created 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkBitmapCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkResourceCache.h" 9 #include "SkResourceCache.h"
10 10
11 namespace { 11 namespace {
12 static void* gGlobalAddress; 12 static void* gGlobalAddress;
13 class TestKey : public SkResourceCache::Key { 13 class TestKey : public SkResourceCache::Key {
14 public: 14 public:
15 void* fPtr; 15 void* fPtr;
16 intptr_t fValue; 16 intptr_t fValue;
17 17
18 TestKey(intptr_t value) : fPtr(&gGlobalAddress), fValue(value) { 18 TestKey(intptr_t value) : fPtr(&gGlobalAddress), fValue(value) {
19 this->init(sizeof(fPtr) + sizeof(fValue)); 19 this->init(sizeof(fPtr) + sizeof(fValue));
20 } 20 }
21 }; 21 };
22 struct TestRec : public SkResourceCache::Rec { 22 struct TestRec : public SkResourceCache::Rec {
23 TestKey fKey; 23 TestKey fKey;
24 intptr_t fValue; 24 intptr_t fValue;
25 25
26 TestRec(const TestKey& key, intptr_t value) : fKey(key), fValue(value) {} 26 TestRec(const TestKey& key, intptr_t value) : fKey(key), fValue(value) {}
27 27
28 virtual const Key& getKey() const SK_OVERRIDE { return fKey; } 28 virtual const Key& getKey() const SK_OVERRIDE { return fKey; }
29 virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + sizeof( fValue); } 29 virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + sizeof( fValue); }
30
31 static bool Visitor(const SkResourceCache::Rec&, void*) {
32 return true;
33 }
30 }; 34 };
31 } 35 }
32 36
33 class ImageCacheBench : public Benchmark { 37 class ImageCacheBench : public Benchmark {
34 SkResourceCache fCache; 38 SkResourceCache fCache;
35 39
36 enum { 40 enum {
37 CACHE_COUNT = 500 41 CACHE_COUNT = 500
38 }; 42 };
39 public: 43 public:
40 ImageCacheBench() : fCache(CACHE_COUNT * 100) {} 44 ImageCacheBench() : fCache(CACHE_COUNT * 100) {}
41 45
42 void populateCache() { 46 void populateCache() {
43 for (int i = 0; i < CACHE_COUNT; ++i) { 47 for (int i = 0; i < CACHE_COUNT; ++i) {
44 fCache.unlock(fCache.addAndLock(SkNEW_ARGS(TestRec, (TestKey(i), i)) )); 48 fCache.add(SkNEW_ARGS(TestRec, (TestKey(i), i)));
45 } 49 }
46 } 50 }
47 51
48 protected: 52 protected:
49 virtual const char* onGetName() SK_OVERRIDE { 53 virtual const char* onGetName() SK_OVERRIDE {
50 return "imagecache"; 54 return "imagecache";
51 } 55 }
52 56
53 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { 57 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
54 if (fCache.getTotalBytesUsed() == 0) { 58 if (fCache.getTotalBytesUsed() == 0) {
55 this->populateCache(); 59 this->populateCache();
56 } 60 }
57 61
58 TestKey key(-1); 62 TestKey key(-1);
59 // search for a miss (-1) 63 // search for a miss (-1)
60 for (int i = 0; i < loops; ++i) { 64 for (int i = 0; i < loops; ++i) {
61 SkDEBUGCODE(SkResourceCache::ID id =) fCache.findAndLock(key); 65 SkDEBUGCODE(bool found =) fCache.find(key, TestRec::Visitor, NULL);
62 SkASSERT(NULL == id); 66 SkASSERT(!found);
63 } 67 }
64 } 68 }
65 69
66 private: 70 private:
67 typedef Benchmark INHERITED; 71 typedef Benchmark INHERITED;
68 }; 72 };
69 73
70 /////////////////////////////////////////////////////////////////////////////// 74 ///////////////////////////////////////////////////////////////////////////////
71 75
72 DEF_BENCH( return new ImageCacheBench(); ) 76 DEF_BENCH( return new ImageCacheBench(); )
OLDNEW
« no previous file with comments | « no previous file | src/core/SkBitmapCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698