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.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/private/SkChecksum.h"
|
|
|
|
#include "include/private/SkTemplates.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "src/core/SkMD5.h"
|
|
|
|
#include "src/core/SkOpts.h"
|
2013-01-31 20:36:30 +00:00
|
|
|
|
2013-01-31 19:47:48 +00:00
|
|
|
enum ChecksumType {
|
|
|
|
kMD5_ChecksumType,
|
2016-08-08 16:06:27 +00:00
|
|
|
kHash_ChecksumType,
|
2013-01-31 19:47:48 +00:00
|
|
|
};
|
2012-06-27 20:03:16 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class ComputeChecksumBench : public Benchmark {
|
2012-06-27 20:03:16 +00:00
|
|
|
enum {
|
2012-07-09 17:44:44 +00:00
|
|
|
U32COUNT = 256,
|
|
|
|
SIZE = U32COUNT * 4,
|
2012-06-27 20:03:16 +00:00
|
|
|
};
|
2012-07-09 17:44:44 +00:00
|
|
|
uint32_t fData[U32COUNT];
|
2013-01-31 19:47:48 +00:00
|
|
|
ChecksumType fType;
|
2012-06-27 20:03:16 +00:00
|
|
|
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
ComputeChecksumBench(ChecksumType type) : fType(type) {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-07-09 17:44:44 +00:00
|
|
|
for (int i = 0; i < U32COUNT; ++i) {
|
|
|
|
fData[i] = rand.nextU();
|
2012-06-27 20:03:16 +00:00
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2012-06-27 20:03:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2013-01-31 19:47:48 +00:00
|
|
|
switch (fType) {
|
|
|
|
case kMD5_ChecksumType: return "compute_md5";
|
2016-08-08 16:06:27 +00:00
|
|
|
case kHash_ChecksumType: return "compute_hash";
|
2013-07-23 20:25:34 +00:00
|
|
|
|
2016-01-29 16:51:04 +00:00
|
|
|
default: SK_ABORT("Invalid Type"); return "";
|
2013-01-31 19:47:48 +00:00
|
|
|
}
|
2012-06-27 20:03:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-01-31 19:47:48 +00:00
|
|
|
switch (fType) {
|
|
|
|
case kMD5_ChecksumType: {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-01-31 19:47:48 +00:00
|
|
|
SkMD5 md5;
|
2016-04-25 17:29:36 +00:00
|
|
|
md5.write(fData, sizeof(fData));
|
2019-04-03 14:13:45 +00:00
|
|
|
(void)md5.finish();
|
2013-01-31 19:47:48 +00:00
|
|
|
}
|
|
|
|
} break;
|
2016-08-08 16:06:27 +00:00
|
|
|
case kHash_ChecksumType: {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2016-08-08 16:06:27 +00:00
|
|
|
volatile uint32_t result = SkOpts::hash(fData, sizeof(fData));
|
2013-07-23 20:25:34 +00:00
|
|
|
sk_ignore_unused_variable(result);
|
|
|
|
}
|
|
|
|
}break;
|
2012-07-03 19:44:20 +00:00
|
|
|
}
|
2013-01-31 19:47:48 +00:00
|
|
|
|
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:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-06-27 20:03:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new ComputeChecksumBench(kMD5_ChecksumType); )
|
2016-08-08 16:06:27 +00:00
|
|
|
DEF_BENCH( return new ComputeChecksumBench(kHash_ChecksumType); )
|