2012-05-17 14:28:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 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"
|
2012-05-17 14:28:11 +00:00
|
|
|
#include "SkCanvas.h"
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "SkChunkAlloc.h"
|
2012-05-17 14:28:11 +00:00
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class ChunkAllocBench : public Benchmark {
|
2012-05-17 14:28:11 +00:00
|
|
|
SkString fName;
|
|
|
|
size_t fMinSize;
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
ChunkAllocBench(size_t minSize) {
|
2012-05-17 14:28:11 +00:00
|
|
|
fMinSize = minSize;
|
2012-07-09 18:22:08 +00:00
|
|
|
fName.printf("chunkalloc_" SK_SIZE_T_SPECIFIER, minSize);
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
|
|
return backend == kNonRendering_Backend;
|
2012-05-17 14:28:11 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-17 14:28:11 +00:00
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() SK_OVERRIDE {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
|
2012-05-17 14:28:11 +00:00
|
|
|
size_t inc = fMinSize >> 4;
|
|
|
|
SkASSERT(inc > 0);
|
|
|
|
size_t total = fMinSize * 64;
|
|
|
|
|
|
|
|
SkChunkAlloc alloc(fMinSize);
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-05-17 14:28:11 +00:00
|
|
|
size_t size = 0;
|
|
|
|
int calls = 0;
|
|
|
|
while (size < total) {
|
|
|
|
alloc.allocThrow(inc);
|
|
|
|
size += inc;
|
|
|
|
calls += 1;
|
|
|
|
}
|
|
|
|
alloc.reset();
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-17 14:28:11 +00:00
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-05-17 14:28:11 +00:00
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new ChunkAllocBench(64); )
|
|
|
|
DEF_BENCH( return new ChunkAllocBench(8*1024); )
|
2013-09-20 14:31:45 +00:00
|
|
|
|