2014-05-20 14:54:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 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"
|
2014-05-20 14:54:04 +00:00
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkTemplates.h"
|
2014-05-28 22:47:26 +00:00
|
|
|
#include "SkUtils.h"
|
2014-05-20 14:54:04 +00:00
|
|
|
|
|
|
|
template <typename Memcpy32>
|
2014-06-19 19:32:29 +00:00
|
|
|
class Memcpy32Bench : public Benchmark {
|
2014-05-20 14:54:04 +00:00
|
|
|
public:
|
|
|
|
explicit Memcpy32Bench(int count, Memcpy32 memcpy32, const char* name)
|
|
|
|
: fCount(count)
|
|
|
|
, fMemcpy32(memcpy32)
|
|
|
|
, fName(SkStringPrintf("%s_%d", name, count)) {}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2014-05-20 14:54:04 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2014-05-20 14:54:04 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onPreDraw() override {
|
2014-05-20 14:54:04 +00:00
|
|
|
fDst.reset(fCount);
|
|
|
|
fSrc.reset(fCount);
|
|
|
|
|
|
|
|
SkRandom rand;
|
|
|
|
for (int i = 0; i < fCount; i++) {
|
|
|
|
fSrc[i] = rand.nextU();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2014-05-20 14:54:04 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
fMemcpy32(fDst, fSrc, fCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkAutoTMalloc<uint32_t> fDst, fSrc;
|
|
|
|
|
|
|
|
int fCount;
|
|
|
|
Memcpy32 fMemcpy32;
|
|
|
|
const SkString fName;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Memcpy32>
|
|
|
|
static Memcpy32Bench<Memcpy32>* Bench(int count, Memcpy32 memcpy32, const char* name) {
|
|
|
|
return new Memcpy32Bench<Memcpy32>(count, memcpy32, name);
|
|
|
|
}
|
|
|
|
#define BENCH(memcpy32, count) DEF_BENCH(return Bench(count, memcpy32, #memcpy32); )
|
|
|
|
|
|
|
|
|
|
|
|
// Let the libc developers do what they think is best.
|
|
|
|
static void memcpy32_memcpy(uint32_t* dst, const uint32_t* src, int count) {
|
|
|
|
memcpy(dst, src, sizeof(uint32_t) * count);
|
|
|
|
}
|
|
|
|
BENCH(memcpy32_memcpy, 10)
|
|
|
|
BENCH(memcpy32_memcpy, 100)
|
|
|
|
BENCH(memcpy32_memcpy, 1000)
|
|
|
|
BENCH(memcpy32_memcpy, 10000)
|
|
|
|
BENCH(memcpy32_memcpy, 100000)
|
|
|
|
|
2014-05-28 22:47:26 +00:00
|
|
|
// Test our chosen best, from SkUtils.h
|
|
|
|
BENCH(sk_memcpy32, 10)
|
|
|
|
BENCH(sk_memcpy32, 100)
|
|
|
|
BENCH(sk_memcpy32, 1000)
|
|
|
|
BENCH(sk_memcpy32, 10000)
|
|
|
|
BENCH(sk_memcpy32, 100000)
|
|
|
|
|
2014-05-20 14:54:04 +00:00
|
|
|
#undef BENCH
|