2012-06-27 20:03:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#include "SkBenchmark.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkChecksum.h"
|
2012-07-09 17:44:44 +00:00
|
|
|
#include "SkRandom.h"
|
2012-06-27 20:03:16 +00:00
|
|
|
|
|
|
|
class ComputeChecksumBench : public SkBenchmark {
|
|
|
|
enum {
|
2012-07-09 17:44:44 +00:00
|
|
|
U32COUNT = 256,
|
|
|
|
SIZE = U32COUNT * 4,
|
2012-06-27 20:03:16 +00:00
|
|
|
N = SkBENCHLOOP(100000),
|
|
|
|
};
|
2012-07-09 17:44:44 +00:00
|
|
|
uint32_t fData[U32COUNT];
|
2012-06-27 20:03:16 +00:00
|
|
|
|
|
|
|
public:
|
2012-07-09 17:44:44 +00:00
|
|
|
ComputeChecksumBench(void* param) : INHERITED(param) {
|
|
|
|
SkRandom rand;
|
|
|
|
for (int i = 0; i < U32COUNT; ++i) {
|
|
|
|
fData[i] = rand.nextU();
|
2012-06-27 20:03:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2012-07-09 17:44:44 +00:00
|
|
|
virtual const char* onGetName() {
|
|
|
|
return "compute_checksum";
|
2012-06-27 20:03:16 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 17:44:44 +00:00
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
2012-07-03 19:44:20 +00:00
|
|
|
for (int i = 0; i < N; i++) {
|
2012-07-09 17:44:44 +00:00
|
|
|
volatile uint32_t result = SkChecksum::Compute(fData, sizeof(fData));
|
2012-07-03 19:44:20 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-09 17:44:44 +00:00
|
|
|
|
2012-06-27 20:03:16 +00:00
|
|
|
private:
|
2012-07-09 17:44:44 +00:00
|
|
|
typedef SkBenchmark INHERITED;
|
2012-06-27 20:03:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-07-09 17:44:44 +00:00
|
|
|
static SkBenchmark* Fact0(void* p) { return new ComputeChecksumBench(p); }
|
2012-06-27 20:03:16 +00:00
|
|
|
|
|
|
|
static BenchRegistry gReg0(Fact0);
|