blob: 3dff98f8c1a6e94e5cf6ec59d20cc24841a44497 [file] [log] [blame]
reed@google.comebd24962012-05-17 14:28:11 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkBenchmark.h"
9#include "SkCanvas.h"
10#include "SkPaint.h"
11#include "SkRandom.h"
12#include "SkChunkAlloc.h"
13#include "SkString.h"
14
15class ChunkAllocBench : public SkBenchmark {
16 SkString fName;
17 size_t fMinSize;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000018
reed@google.comebd24962012-05-17 14:28:11 +000019 enum {
20 N = SkBENCHLOOP(1000)
21 };
22public:
23 ChunkAllocBench(void* param, size_t minSize) : INHERITED(param) {
24 fMinSize = minSize;
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +000025 fName.printf("chunkalloc_" SK_SIZE_T_SPECIFIER, minSize);
tomhudson@google.com9dc27132012-09-13 15:50:24 +000026 fIsRendering = false;
reed@google.comebd24962012-05-17 14:28:11 +000027 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000028
reed@google.comebd24962012-05-17 14:28:11 +000029protected:
30 virtual const char* onGetName() SK_OVERRIDE {
31 return fName.c_str();
32 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000033
sugoi@google.com77472f02013-03-05 18:50:01 +000034 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
reed@google.comebd24962012-05-17 14:28:11 +000035 size_t inc = fMinSize >> 4;
36 SkASSERT(inc > 0);
37 size_t total = fMinSize * 64;
38
39 SkChunkAlloc alloc(fMinSize);
40
41 for (int i = 0; i < N; ++i) {
42 size_t size = 0;
43 int calls = 0;
44 while (size < total) {
45 alloc.allocThrow(inc);
46 size += inc;
47 calls += 1;
48 }
49 alloc.reset();
50 }
51 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000052
reed@google.comebd24962012-05-17 14:28:11 +000053private:
54 typedef SkBenchmark INHERITED;
55};
56
57static SkBenchmark* F0(void* p) { return new ChunkAllocBench(p, 64); }
58static SkBenchmark* F1(void* p) { return new ChunkAllocBench(p, 8*1024); }
59
60static BenchRegistry gR0(F0);
61static BenchRegistry gR1(F1);