| OLD | NEW |
| 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 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 SkResourceCache fCache; | 39 SkResourceCache fCache; |
| 40 | 40 |
| 41 enum { | 41 enum { |
| 42 CACHE_COUNT = 500 | 42 CACHE_COUNT = 500 |
| 43 }; | 43 }; |
| 44 public: | 44 public: |
| 45 ImageCacheBench() : fCache(CACHE_COUNT * 100) {} | 45 ImageCacheBench() : fCache(CACHE_COUNT * 100) {} |
| 46 | 46 |
| 47 void populateCache() { | 47 void populateCache() { |
| 48 for (int i = 0; i < CACHE_COUNT; ++i) { | 48 for (int i = 0; i < CACHE_COUNT; ++i) { |
| 49 fCache.add(SkNEW_ARGS(TestRec, (TestKey(i), i))); | 49 fCache.add(new TestRec(TestKey(i), i)); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 protected: | 53 protected: |
| 54 const char* onGetName() override { | 54 const char* onGetName() override { |
| 55 return "imagecache"; | 55 return "imagecache"; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void onDraw(const int loops, SkCanvas*) override { | 58 void onDraw(const int loops, SkCanvas*) override { |
| 59 if (fCache.getTotalBytesUsed() == 0) { | 59 if (fCache.getTotalBytesUsed() == 0) { |
| 60 this->populateCache(); | 60 this->populateCache(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 TestKey key(-1); | 63 TestKey key(-1); |
| 64 // search for a miss (-1) | 64 // search for a miss (-1) |
| 65 for (int i = 0; i < loops; ++i) { | 65 for (int i = 0; i < loops; ++i) { |
| 66 SkDEBUGCODE(bool found =) fCache.find(key, TestRec::Visitor, NULL); | 66 SkDEBUGCODE(bool found =) fCache.find(key, TestRec::Visitor, NULL); |
| 67 SkASSERT(!found); | 67 SkASSERT(!found); |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 typedef Benchmark INHERITED; | 72 typedef Benchmark INHERITED; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 /////////////////////////////////////////////////////////////////////////////// | 75 /////////////////////////////////////////////////////////////////////////////// |
| 76 | 76 |
| 77 DEF_BENCH( return new ImageCacheBench(); ) | 77 DEF_BENCH( return new ImageCacheBench(); ) |
| OLD | NEW |