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.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2012-06-27 20:03:16 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkChecksum.h"
|
2013-01-31 19:47:48 +00:00
|
|
|
#include "SkMD5.h"
|
2012-07-09 17:44:44 +00:00
|
|
|
#include "SkRandom.h"
|
2013-01-31 19:47:48 +00:00
|
|
|
#include "SkSHA1.h"
|
2013-02-04 15:58:08 +00:00
|
|
|
#include "SkTemplates.h"
|
2013-01-31 20:36:30 +00:00
|
|
|
|
2013-01-31 19:47:48 +00:00
|
|
|
enum ChecksumType {
|
|
|
|
kMD5_ChecksumType,
|
2013-07-23 20:25:34 +00:00
|
|
|
kSHA1_ChecksumType,
|
|
|
|
kMurmur3_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";
|
|
|
|
case kSHA1_ChecksumType: return "compute_sha1";
|
2013-07-23 20:25:34 +00:00
|
|
|
case kMurmur3_ChecksumType: return "compute_murmur3";
|
|
|
|
|
2013-01-31 19:47:48 +00:00
|
|
|
default: SK_CRASH(); return "";
|
|
|
|
}
|
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;
|
|
|
|
md5.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData));
|
|
|
|
SkMD5::Digest digest;
|
|
|
|
md5.finish(digest);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case kSHA1_ChecksumType: {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-01-31 19:47:48 +00:00
|
|
|
SkSHA1 sha1;
|
|
|
|
sha1.update(reinterpret_cast<uint8_t*>(fData), sizeof(fData));
|
|
|
|
SkSHA1::Digest digest;
|
|
|
|
sha1.finish(digest);
|
|
|
|
}
|
|
|
|
} break;
|
2013-07-23 20:25:34 +00:00
|
|
|
case kMurmur3_ChecksumType: {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-07-23 20:25:34 +00:00
|
|
|
volatile uint32_t result = SkChecksum::Murmur3(fData, sizeof(fData));
|
|
|
|
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); )
|
|
|
|
DEF_BENCH( return new ComputeChecksumBench(kSHA1_ChecksumType); )
|
|
|
|
DEF_BENCH( return new ComputeChecksumBench(kMurmur3_ChecksumType); )
|