blob: affae2902e2bce3b6a139deac53850d743e7c248 [file] [log] [blame]
reed@google.comc117cba2013-06-03 16:54:10 +00001/*
2 * Copyright 2013 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 "SkUtils.h"
11#include "SkString.h"
12
13class MemsetBench : public SkBenchmark {
14 SkString fName;
15
16protected:
17 size_t fMinSize;
18 size_t fMaxSize;
19 enum {
reed@google.comc117cba2013-06-03 16:54:10 +000020 kBufferSize = 10000,
21 VALUE32 = 0x12345678,
22 VALUE16 = 0x1234
23 };
24
25 enum MemsetType {
26 MEMSET16 = 16,
27 MEMSET32 = 32
28 };
29
30public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000031 MemsetBench(MemsetType type, size_t minSize, size_t maxSize) {
reed@google.comc117cba2013-06-03 16:54:10 +000032 SkASSERT((minSize < maxSize) && (maxSize <= kBufferSize));
33 fMinSize = minSize;
34 fMaxSize = maxSize;
35 fName.printf("memset%d_" SK_SIZE_T_SPECIFIER "_" SK_SIZE_T_SPECIFIER,
36 type, minSize, maxSize);
37 fIsRendering = false;
38 }
39
40 virtual void performTest() = 0;
41
42protected:
43 virtual const char* onGetName() SK_OVERRIDE {
44 return fName.c_str();
45 }
46
47 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
mtklein@google.comc2897432013-09-10 19:23:38 +000048 for (int i = 0; i < this->getLoops(); ++i) {
reed@google.comc117cba2013-06-03 16:54:10 +000049 this->performTest();
50 }
51 }
52
53private:
54 typedef SkBenchmark INHERITED;
55};
56
57class Memset32Bench : public MemsetBench {
58 uint32_t kBuffer[kBufferSize + 3];
59public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000060 Memset32Bench(size_t minSize, size_t maxSize)
61 : INHERITED(MEMSET32, minSize, maxSize) {}
reed@google.comc117cba2013-06-03 16:54:10 +000062
63protected:
robertphillips@google.com59ce1372013-06-03 17:29:58 +000064 virtual void performTest() SK_OVERRIDE {
reed@google.comc117cba2013-06-03 16:54:10 +000065 for(size_t j = fMinSize; j < fMaxSize; ++j){
66 sk_memset32(kBuffer, VALUE32, j);
67 sk_memset32(kBuffer + 1, VALUE32, j);
68 sk_memset32(kBuffer + 2, VALUE32, j);
69 sk_memset32(kBuffer + 3, VALUE32, j);
70 }
71 }
72private:
73 typedef MemsetBench INHERITED;
74};
75
76class Memset16Bench : public MemsetBench {
77 uint16_t kBuffer[kBufferSize + 7];
78public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000079 Memset16Bench(size_t minSize, size_t maxSize)
80 : INHERITED(MEMSET16, minSize, maxSize) {}
reed@google.comc117cba2013-06-03 16:54:10 +000081
82protected:
robertphillips@google.com59ce1372013-06-03 17:29:58 +000083 virtual void performTest() SK_OVERRIDE {
reed@google.comc117cba2013-06-03 16:54:10 +000084 for(size_t j = fMinSize; j < fMaxSize; ++j){
85 sk_memset16(kBuffer, VALUE16, j);
86 sk_memset16(kBuffer + 1, VALUE16, j);
87 sk_memset16(kBuffer + 2, VALUE16, j);
88 sk_memset16(kBuffer + 3, VALUE16, j);
89 sk_memset16(kBuffer + 4, VALUE16, j);
90 sk_memset16(kBuffer + 5, VALUE16, j);
91 sk_memset16(kBuffer + 6, VALUE16, j);
92 sk_memset16(kBuffer + 7, VALUE16, j);
93 }
94 }
95private:
96 typedef MemsetBench INHERITED;
97};
98
mtklein@google.com410e6e82013-09-13 19:52:27 +000099DEF_BENCH(return new Memset32Bench(1, 600);)
100DEF_BENCH(return new Memset32Bench(600, 800);)
101DEF_BENCH(return new Memset32Bench(800, 1000);)
102DEF_BENCH(return new Memset32Bench(1000, 2000);)
103DEF_BENCH(return new Memset32Bench(2000, 3000);)
104DEF_BENCH(return new Memset32Bench(3000, 4000);)
105DEF_BENCH(return new Memset32Bench(4000, 5000);)
reed@google.comc117cba2013-06-03 16:54:10 +0000106
mtklein@google.com410e6e82013-09-13 19:52:27 +0000107DEF_BENCH(return new Memset16Bench(1, 600);)
108DEF_BENCH(return new Memset16Bench(600, 800);)
109DEF_BENCH(return new Memset16Bench(800, 1000);)
110DEF_BENCH(return new Memset16Bench(1000, 2000);)
111DEF_BENCH(return new Memset16Bench(2000, 3000);)
112DEF_BENCH(return new Memset16Bench(3000, 4000);)
113DEF_BENCH(return new Memset16Bench(4000, 5000);)