blob: ae14dac6a43a49c0c57eaf50382016a111b39f16 [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;
reed@google.comebd24962012-05-17 14:28:11 +000018public:
19 ChunkAllocBench(void* param, size_t minSize) : INHERITED(param) {
20 fMinSize = minSize;
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +000021 fName.printf("chunkalloc_" SK_SIZE_T_SPECIFIER, minSize);
tomhudson@google.com9dc27132012-09-13 15:50:24 +000022 fIsRendering = false;
reed@google.comebd24962012-05-17 14:28:11 +000023 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000024
reed@google.comebd24962012-05-17 14:28:11 +000025protected:
26 virtual const char* onGetName() SK_OVERRIDE {
27 return fName.c_str();
28 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000029
sugoi@google.com77472f02013-03-05 18:50:01 +000030 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
reed@google.comebd24962012-05-17 14:28:11 +000031 size_t inc = fMinSize >> 4;
32 SkASSERT(inc > 0);
33 size_t total = fMinSize * 64;
34
35 SkChunkAlloc alloc(fMinSize);
36
mtklein@google.comc2897432013-09-10 19:23:38 +000037 for (int i = 0; i < this->getLoops(); ++i) {
reed@google.comebd24962012-05-17 14:28:11 +000038 size_t size = 0;
39 int calls = 0;
40 while (size < total) {
41 alloc.allocThrow(inc);
42 size += inc;
43 calls += 1;
44 }
45 alloc.reset();
46 }
47 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000048
reed@google.comebd24962012-05-17 14:28:11 +000049private:
50 typedef SkBenchmark INHERITED;
51};
52
53static SkBenchmark* F0(void* p) { return new ChunkAllocBench(p, 64); }
54static SkBenchmark* F1(void* p) { return new ChunkAllocBench(p, 8*1024); }
55
56static BenchRegistry gR0(F0);
57static BenchRegistry gR1(F1);