blob: fe3fd477896082180d1220a4a5b1ad13287c74c9 [file] [log] [blame]
junov@chromium.orgef760602012-06-27 20:03:16 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#include "SkBenchmark.h"
8#include "SkCanvas.h"
9#include "SkChecksum.h"
reed@google.com142e1fe2012-07-09 17:44:44 +000010#include "SkRandom.h"
junov@chromium.orgef760602012-06-27 20:03:16 +000011
12class ComputeChecksumBench : public SkBenchmark {
reed@google.comfc8581b2012-07-09 17:40:48 +000013 enum {
reed@google.com142e1fe2012-07-09 17:44:44 +000014 U32COUNT = 256,
15 SIZE = U32COUNT * 4,
reed@google.comfc8581b2012-07-09 17:40:48 +000016 N = SkBENCHLOOP(100000),
17 };
reed@google.com142e1fe2012-07-09 17:44:44 +000018 uint32_t fData[U32COUNT];
19
20public:
21 ComputeChecksumBench(void* param) : INHERITED(param) {
22 SkRandom rand;
23 for (int i = 0; i < U32COUNT; ++i) {
24 fData[i] = rand.nextU();
25 }
26 }
27
junov@chromium.orgef760602012-06-27 20:03:16 +000028protected:
29 virtual const char* onGetName() {
reed@google.com142e1fe2012-07-09 17:44:44 +000030 return "compute_checksum";
junov@chromium.orgef760602012-06-27 20:03:16 +000031 }
32
33 virtual void onDraw(SkCanvas* canvas) {
reed@google.com142e1fe2012-07-09 17:44:44 +000034 for (int i = 0; i < N; i++) {
35 volatile uint32_t result = SkChecksum::Compute(fData, sizeof(fData));
36 }
junov@chromium.orgef760602012-06-27 20:03:16 +000037 }
38
junov@chromium.orgef760602012-06-27 20:03:16 +000039private:
40 typedef SkBenchmark INHERITED;
41};
42
junov@chromium.orgef760602012-06-27 20:03:16 +000043///////////////////////////////////////////////////////////////////////////////
44
reed@google.com142e1fe2012-07-09 17:44:44 +000045static SkBenchmark* Fact0(void* p) { return new ComputeChecksumBench(p); }
junov@chromium.orgef760602012-06-27 20:03:16 +000046
47static BenchRegistry gReg0(Fact0);