2013-06-03 16:54:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2013-06-03 16:54:10 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkString.h"
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "SkUtils.h"
|
2013-06-03 16:54:10 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class MemsetBench : public Benchmark {
|
2013-06-03 16:54:10 +00:00
|
|
|
SkString fName;
|
|
|
|
|
|
|
|
protected:
|
2014-12-15 17:13:35 +00:00
|
|
|
int fMinSize;
|
|
|
|
int fMaxSize;
|
2013-06-03 16:54:10 +00:00
|
|
|
enum {
|
|
|
|
kBufferSize = 10000,
|
|
|
|
VALUE32 = 0x12345678,
|
|
|
|
VALUE16 = 0x1234
|
|
|
|
};
|
|
|
|
|
|
|
|
enum MemsetType {
|
|
|
|
MEMSET16 = 16,
|
|
|
|
MEMSET32 = 32
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2014-12-15 17:13:35 +00:00
|
|
|
MemsetBench(MemsetType type, int minSize, int maxSize) {
|
2013-06-03 16:54:10 +00:00
|
|
|
SkASSERT((minSize < maxSize) && (maxSize <= kBufferSize));
|
|
|
|
fMinSize = minSize;
|
|
|
|
fMaxSize = maxSize;
|
2014-12-15 17:13:35 +00:00
|
|
|
fName.printf("memset%d_%d_%d", type, minSize, maxSize);
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2013-06-03 16:54:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void performTest() = 0;
|
|
|
|
|
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
const char* onGetName() SK_OVERRIDE {
|
2013-06-03 16:54:10 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-06-03 16:54:10 +00:00
|
|
|
this->performTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-06-03 16:54:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Memset32Bench : public MemsetBench {
|
|
|
|
uint32_t kBuffer[kBufferSize + 3];
|
|
|
|
public:
|
2014-12-15 17:13:35 +00:00
|
|
|
Memset32Bench(int minSize, int maxSize)
|
2013-09-13 19:52:27 +00:00
|
|
|
: INHERITED(MEMSET32, minSize, maxSize) {}
|
2013-06-03 16:54:10 +00:00
|
|
|
|
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
void performTest() SK_OVERRIDE {
|
2014-12-15 17:13:35 +00:00
|
|
|
for(int j = fMinSize; j < fMaxSize; ++j){
|
2013-06-03 16:54:10 +00:00
|
|
|
sk_memset32(kBuffer, VALUE32, j);
|
|
|
|
sk_memset32(kBuffer + 1, VALUE32, j);
|
|
|
|
sk_memset32(kBuffer + 2, VALUE32, j);
|
|
|
|
sk_memset32(kBuffer + 3, VALUE32, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef MemsetBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Memset16Bench : public MemsetBench {
|
|
|
|
uint16_t kBuffer[kBufferSize + 7];
|
|
|
|
public:
|
2014-12-15 17:13:35 +00:00
|
|
|
Memset16Bench(int minSize, int maxSize)
|
2013-09-13 19:52:27 +00:00
|
|
|
: INHERITED(MEMSET16, minSize, maxSize) {}
|
2013-06-03 16:54:10 +00:00
|
|
|
|
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
void performTest() SK_OVERRIDE {
|
2014-12-15 17:13:35 +00:00
|
|
|
for(int j = fMinSize; j < fMaxSize; ++j){
|
2013-06-03 16:54:10 +00:00
|
|
|
sk_memset16(kBuffer, VALUE16, j);
|
|
|
|
sk_memset16(kBuffer + 1, VALUE16, j);
|
|
|
|
sk_memset16(kBuffer + 2, VALUE16, j);
|
|
|
|
sk_memset16(kBuffer + 3, VALUE16, j);
|
|
|
|
sk_memset16(kBuffer + 4, VALUE16, j);
|
|
|
|
sk_memset16(kBuffer + 5, VALUE16, j);
|
|
|
|
sk_memset16(kBuffer + 6, VALUE16, j);
|
|
|
|
sk_memset16(kBuffer + 7, VALUE16, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef MemsetBench INHERITED;
|
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH(return new Memset32Bench(1, 600);)
|
|
|
|
DEF_BENCH(return new Memset32Bench(600, 800);)
|
|
|
|
DEF_BENCH(return new Memset32Bench(800, 1000);)
|
|
|
|
DEF_BENCH(return new Memset32Bench(1000, 2000);)
|
|
|
|
DEF_BENCH(return new Memset32Bench(2000, 3000);)
|
|
|
|
DEF_BENCH(return new Memset32Bench(3000, 4000);)
|
|
|
|
DEF_BENCH(return new Memset32Bench(4000, 5000);)
|
2013-06-03 16:54:10 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH(return new Memset16Bench(1, 600);)
|
|
|
|
DEF_BENCH(return new Memset16Bench(600, 800);)
|
|
|
|
DEF_BENCH(return new Memset16Bench(800, 1000);)
|
|
|
|
DEF_BENCH(return new Memset16Bench(1000, 2000);)
|
|
|
|
DEF_BENCH(return new Memset16Bench(2000, 3000);)
|
|
|
|
DEF_BENCH(return new Memset16Bench(3000, 4000);)
|
|
|
|
DEF_BENCH(return new Memset16Bench(4000, 5000);)
|