blob: 2b0f2abc7944a29da6cc80debe6099425c8878fe [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
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
reed@google.comebd24962012-05-17 14:28:11 +00009#include "SkCanvas.h"
tfarinaf168b862014-06-19 12:32:29 -070010#include "SkChunkAlloc.h"
reed@google.comebd24962012-05-17 14:28:11 +000011#include "SkPaint.h"
12#include "SkRandom.h"
reed@google.comebd24962012-05-17 14:28:11 +000013#include "SkString.h"
14
tfarinaf168b862014-06-19 12:32:29 -070015class ChunkAllocBench : public Benchmark {
reed@google.comebd24962012-05-17 14:28:11 +000016 SkString fName;
17 size_t fMinSize;
reed@google.comebd24962012-05-17 14:28:11 +000018public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000019 ChunkAllocBench(size_t minSize) {
reed@google.comebd24962012-05-17 14:28:11 +000020 fMinSize = minSize;
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +000021 fName.printf("chunkalloc_" SK_SIZE_T_SPECIFIER, minSize);
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000022 }
23
mtklein36352bf2015-03-25 18:17:31 -070024 bool isSuitableFor(Backend backend) override {
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000025 return backend == kNonRendering_Backend;
reed@google.comebd24962012-05-17 14:28:11 +000026 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000027
reed@google.comebd24962012-05-17 14:28:11 +000028protected:
mtklein36352bf2015-03-25 18:17:31 -070029 const char* onGetName() override {
reed@google.comebd24962012-05-17 14:28:11 +000030 return fName.c_str();
31 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000032
mtklein36352bf2015-03-25 18:17:31 -070033 void onDraw(const int loops, SkCanvas*) override {
reed@google.comebd24962012-05-17 14:28:11 +000034 size_t inc = fMinSize >> 4;
35 SkASSERT(inc > 0);
36 size_t total = fMinSize * 64;
37
38 SkChunkAlloc alloc(fMinSize);
39
commit-bot@chromium.org33614712013-12-03 18:17:16 +000040 for (int i = 0; i < loops; ++i) {
reed@google.comebd24962012-05-17 14:28:11 +000041 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 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000051
reed@google.comebd24962012-05-17 14:28:11 +000052private:
tfarinaf168b862014-06-19 12:32:29 -070053 typedef Benchmark INHERITED;
reed@google.comebd24962012-05-17 14:28:11 +000054};
55
mtklein@google.com410e6e82013-09-13 19:52:27 +000056DEF_BENCH( return new ChunkAllocBench(64); )
57DEF_BENCH( return new ChunkAllocBench(8*1024); )
mtklein@google.com519f9672013-09-20 14:31:45 +000058