blob: 818b9e367bee2853092b8761290757949968e2f4 [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 }
robertphillips@google.com433ce5e2012-09-17 10:49:30 +000026 fIsRendering = false;
reed@google.com142e1fe2012-07-09 17:44:44 +000027 }
28
junov@chromium.orgef760602012-06-27 20:03:16 +000029protected:
30 virtual const char* onGetName() {
reed@google.com142e1fe2012-07-09 17:44:44 +000031 return "compute_checksum";
junov@chromium.orgef760602012-06-27 20:03:16 +000032 }
33
34 virtual void onDraw(SkCanvas* canvas) {
reed@google.com142e1fe2012-07-09 17:44:44 +000035 for (int i = 0; i < N; i++) {
36 volatile uint32_t result = SkChecksum::Compute(fData, sizeof(fData));
37 }
junov@chromium.orgef760602012-06-27 20:03:16 +000038 }
39
junov@chromium.orgef760602012-06-27 20:03:16 +000040private:
41 typedef SkBenchmark INHERITED;
42};
43
junov@chromium.orgef760602012-06-27 20:03:16 +000044///////////////////////////////////////////////////////////////////////////////
45
reed@google.com142e1fe2012-07-09 17:44:44 +000046static SkBenchmark* Fact0(void* p) { return new ComputeChecksumBench(p); }
junov@chromium.orgef760602012-06-27 20:03:16 +000047
48static BenchRegistry gReg0(Fact0);