skia2/bench/MemoryBench.cpp
mtklein@google.com 410e6e80f0 Refactoring: get rid of the SkBenchmark void* parameter.
While I was doing massive sed-ing, I also converted every bench to use DEF_BENCH instead of registering the ugly manual way.

BUG=
R=scroggo@google.com

Review URL: https://codereview.chromium.org/23876006

git-svn-id: http://skia.googlecode.com/svn/trunk@11263 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-13 19:52:27 +00:00

55 lines
1.3 KiB
C++

/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBenchmark.h"
#include "SkCanvas.h"
#include "SkPaint.h"
#include "SkRandom.h"
#include "SkChunkAlloc.h"
#include "SkString.h"
class ChunkAllocBench : public SkBenchmark {
SkString fName;
size_t fMinSize;
public:
ChunkAllocBench(size_t minSize) {
fMinSize = minSize;
fName.printf("chunkalloc_" SK_SIZE_T_SPECIFIER, minSize);
fIsRendering = false;
}
protected:
virtual const char* onGetName() SK_OVERRIDE {
return fName.c_str();
}
virtual void onDraw(SkCanvas*) SK_OVERRIDE {
size_t inc = fMinSize >> 4;
SkASSERT(inc > 0);
size_t total = fMinSize * 64;
SkChunkAlloc alloc(fMinSize);
for (int i = 0; i < this->getLoops(); ++i) {
size_t size = 0;
int calls = 0;
while (size < total) {
alloc.allocThrow(inc);
size += inc;
calls += 1;
}
alloc.reset();
}
}
private:
typedef SkBenchmark INHERITED;
};
DEF_BENCH( return new ChunkAllocBench(64); )
DEF_BENCH( return new ChunkAllocBench(8*1024); )