blob: e732687a961b455094ba099a40e97502617eee31 [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;
18
19 enum {
20 N = SkBENCHLOOP(1000)
21 };
22public:
23 ChunkAllocBench(void* param, size_t minSize) : INHERITED(param) {
24 fMinSize = minSize;
25 fName.printf("chunkalloc_%d", minSize);
26 }
27
28protected:
29 virtual const char* onGetName() SK_OVERRIDE {
30 return fName.c_str();
31 }
32
33 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
34 size_t inc = fMinSize >> 4;
35 SkASSERT(inc > 0);
36 size_t total = fMinSize * 64;
37
38 SkChunkAlloc alloc(fMinSize);
39
40 for (int i = 0; i < N; ++i) {
41 size_t size = 0;
42 int calls = 0;
43 while (size < total) {
44 alloc.allocThrow(inc);
45 size += inc;
46 calls += 1;
47 }
48 alloc.reset();
49 }
50 }
51
52private:
53 typedef SkBenchmark INHERITED;
54};
55
56static SkBenchmark* F0(void* p) { return new ChunkAllocBench(p, 64); }
57static SkBenchmark* F1(void* p) { return new ChunkAllocBench(p, 8*1024); }
58
59static BenchRegistry gR0(F0);
60static BenchRegistry gR1(F1);
61