reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "Benchmark.h" |
reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 10 | #include "SkChunkAlloc.h" |
reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 11 | #include "SkPaint.h" |
| 12 | #include "SkRandom.h" |
reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 13 | #include "SkString.h" |
| 14 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 15 | class ChunkAllocBench : public Benchmark { |
reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 16 | SkString fName; |
| 17 | size_t fMinSize; |
reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 18 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 19 | ChunkAllocBench(size_t minSize) { |
reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 20 | fMinSize = minSize; |
senorblanco@chromium.org | 3a67a66 | 2012-07-09 18:22:08 +0000 | [diff] [blame] | 21 | fName.printf("chunkalloc_" SK_SIZE_T_SPECIFIER, minSize); |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 22 | } |
| 23 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 24 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 25 | return backend == kNonRendering_Backend; |
reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 26 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 27 | |
reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 28 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 29 | const char* onGetName() override { |
reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 30 | return fName.c_str(); |
| 31 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 32 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 33 | void onDraw(int loops, SkCanvas*) override { |
reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 34 | size_t inc = fMinSize >> 4; |
| 35 | SkASSERT(inc > 0); |
| 36 | size_t total = fMinSize * 64; |
| 37 | |
| 38 | SkChunkAlloc alloc(fMinSize); |
| 39 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 40 | for (int i = 0; i < loops; ++i) { |
reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 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 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 51 | |
reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 52 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 53 | typedef Benchmark INHERITED; |
reed@google.com | ebd2496 | 2012-05-17 14:28:11 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 56 | DEF_BENCH( return new ChunkAllocBench(64); ) |
| 57 | DEF_BENCH( return new ChunkAllocBench(8*1024); ) |
mtklein@google.com | 519f967 | 2013-09-20 14:31:45 +0000 | [diff] [blame] | 58 | |