2013-07-23 19:13:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2014-08-28 20:35:23 +00:00
|
|
|
#include "SkResourceCache.h"
|
2013-07-23 19:13:54 +00:00
|
|
|
|
2014-08-21 16:46:49 +00:00
|
|
|
namespace {
|
|
|
|
static void* gGlobalAddress;
|
2014-08-28 20:35:23 +00:00
|
|
|
class TestKey : public SkResourceCache::Key {
|
2014-08-21 16:46:49 +00:00
|
|
|
public:
|
|
|
|
intptr_t fValue;
|
|
|
|
|
2014-10-22 18:20:40 +00:00
|
|
|
TestKey(intptr_t value) : fValue(value) {
|
|
|
|
this->init(&gGlobalAddress, sizeof(fValue));
|
2014-08-21 16:46:49 +00:00
|
|
|
}
|
|
|
|
};
|
2014-08-28 20:35:23 +00:00
|
|
|
struct TestRec : public SkResourceCache::Rec {
|
2014-08-26 16:08:04 +00:00
|
|
|
TestKey fKey;
|
|
|
|
intptr_t fValue;
|
|
|
|
|
|
|
|
TestRec(const TestKey& key, intptr_t value) : fKey(key), fValue(value) {}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
const Key& getKey() const SK_OVERRIDE { return fKey; }
|
|
|
|
size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + sizeof(fValue); }
|
2014-09-15 18:39:44 +00:00
|
|
|
|
|
|
|
static bool Visitor(const SkResourceCache::Rec&, void*) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-08-26 16:08:04 +00:00
|
|
|
};
|
2014-08-21 16:46:49 +00:00
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class ImageCacheBench : public Benchmark {
|
2014-08-28 20:35:23 +00:00
|
|
|
SkResourceCache fCache;
|
2013-07-23 19:13:54 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
CACHE_COUNT = 500
|
|
|
|
};
|
|
|
|
public:
|
2014-08-28 20:35:23 +00:00
|
|
|
ImageCacheBench() : fCache(CACHE_COUNT * 100) {}
|
2013-07-23 19:13:54 +00:00
|
|
|
|
|
|
|
void populateCache() {
|
|
|
|
for (int i = 0; i < CACHE_COUNT; ++i) {
|
2014-09-15 18:39:44 +00:00
|
|
|
fCache.add(SkNEW_ARGS(TestRec, (TestKey(i), i)));
|
2013-07-23 19:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
const char* onGetName() SK_OVERRIDE {
|
2013-07-23 19:13:54 +00:00
|
|
|
return "imagecache";
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
|
2014-07-17 13:58:01 +00:00
|
|
|
if (fCache.getTotalBytesUsed() == 0) {
|
2013-07-23 19:13:54 +00:00
|
|
|
this->populateCache();
|
|
|
|
}
|
|
|
|
|
2014-08-21 16:46:49 +00:00
|
|
|
TestKey key(-1);
|
2014-08-26 16:08:04 +00:00
|
|
|
// search for a miss (-1)
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2014-09-15 18:39:44 +00:00
|
|
|
SkDEBUGCODE(bool found =) fCache.find(key, TestRec::Visitor, NULL);
|
|
|
|
SkASSERT(!found);
|
2013-07-23 19:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-07-23 19:13:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new ImageCacheBench(); )
|