skia2/bench/ImageCacheBench.cpp
mtklein 72c9faab45 Fix up all the easy virtual ... SK_OVERRIDE cases.
This fixes every case where virtual and SK_OVERRIDE were on the same line,
which should be the bulk of cases.  We'll have to manually clean up the rest
over time unless I level up in regexes.

for f in (find . -type f); perl -p -i -e 's/virtual (.*)SK_OVERRIDE/\1SK_OVERRIDE/g' $f; end

BUG=skia:

Review URL: https://codereview.chromium.org/806653007
2015-01-09 10:06:40 -08:00

76 lines
1.8 KiB
C++

/*
* 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 "Benchmark.h"
#include "SkResourceCache.h"
namespace {
static void* gGlobalAddress;
class TestKey : public SkResourceCache::Key {
public:
intptr_t fValue;
TestKey(intptr_t value) : fValue(value) {
this->init(&gGlobalAddress, sizeof(fValue));
}
};
struct TestRec : public SkResourceCache::Rec {
TestKey fKey;
intptr_t fValue;
TestRec(const TestKey& key, intptr_t value) : fKey(key), fValue(value) {}
const Key& getKey() const SK_OVERRIDE { return fKey; }
size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + sizeof(fValue); }
static bool Visitor(const SkResourceCache::Rec&, void*) {
return true;
}
};
}
class ImageCacheBench : public Benchmark {
SkResourceCache fCache;
enum {
CACHE_COUNT = 500
};
public:
ImageCacheBench() : fCache(CACHE_COUNT * 100) {}
void populateCache() {
for (int i = 0; i < CACHE_COUNT; ++i) {
fCache.add(SkNEW_ARGS(TestRec, (TestKey(i), i)));
}
}
protected:
const char* onGetName() SK_OVERRIDE {
return "imagecache";
}
void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
if (fCache.getTotalBytesUsed() == 0) {
this->populateCache();
}
TestKey key(-1);
// search for a miss (-1)
for (int i = 0; i < loops; ++i) {
SkDEBUGCODE(bool found =) fCache.find(key, TestRec::Visitor, NULL);
SkASSERT(!found);
}
}
private:
typedef Benchmark INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
DEF_BENCH( return new ImageCacheBench(); )