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 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 15 class ChunkAllocBench : public SkBenchmark { 16 SkString fName; 17 size_t fMinSize; 18 19 enum { 20 N = SkBENCHLOOP(1000) 21 }; 22 public: ChunkAllocBench(void * param,size_t minSize)23 ChunkAllocBench(void* param, size_t minSize) : INHERITED(param) { 24 fMinSize = minSize; 25 fName.printf("chunkalloc_" SK_SIZE_T_SPECIFIER, minSize); 26 fIsRendering = false; 27 } 28 29 protected: onGetName()30 virtual const char* onGetName() SK_OVERRIDE { 31 return fName.c_str(); 32 } 33 onDraw(SkCanvas * canvas)34 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 35 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 } 52 53 private: 54 typedef SkBenchmark INHERITED; 55 }; 56 F0(void * p)57static SkBenchmark* F0(void* p) { return new ChunkAllocBench(p, 64); } F1(void * p)58static SkBenchmark* F1(void* p) { return new ChunkAllocBench(p, 8*1024); } 59 60 static BenchRegistry gR0(F0); 61 static BenchRegistry gR1(F1); 62