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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "src/core/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) {
|
2015-02-24 21:54:23 +00:00
|
|
|
this->init(&gGlobalAddress, 0, 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-03-26 01:17:31 +00:00
|
|
|
const Key& getKey() const override { return fKey; }
|
|
|
|
size_t bytesUsed() const override { return sizeof(fKey) + sizeof(fValue); }
|
2015-08-19 19:25:40 +00:00
|
|
|
const char* getCategory() const override { return "imagecachebench-test"; }
|
2015-08-27 14:41:13 +00:00
|
|
|
SkDiscardableMemory* diagnostic_only_getDiscardable() const override { return nullptr; }
|
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
|
|
|
};
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace
|
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) {
|
2015-08-26 20:07:48 +00:00
|
|
|
fCache.add(new TestRec(TestKey(i), i));
|
2013-07-23 19:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-07-23 19:13:54 +00:00
|
|
|
return "imagecache";
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) 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) {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkDEBUGCODE(bool found =) fCache.find(key, TestRec::Visitor, nullptr);
|
2014-09-15 18:39:44 +00:00
|
|
|
SkASSERT(!found);
|
2013-07-23 19:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2013-07-23 19:13:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new ImageCacheBench(); )
|