aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/ChecksumBench.cpp
blob: 31160c7ad0b796735c9863875523f99adf99b8f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * 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"
#include "SkRandom.h"

class ComputeChecksumBench : public SkBenchmark {
    enum {
        U32COUNT  = 256,
        SIZE      = U32COUNT * 4,
        N         = SkBENCHLOOP(100000),
    };
    uint32_t    fData[U32COUNT];

public:
    ComputeChecksumBench(void* param) : INHERITED(param) {
        SkRandom rand;
        for (int i = 0; i < U32COUNT; ++i) {
            fData[i] = rand.nextU();
        }
        fIsRendering = false;
    }

protected:
    virtual const char* onGetName() {
        return "compute_checksum";
    }

    virtual void onDraw(SkCanvas* canvas) {
        for (int i = 0; i < N; i++) {
            (void) SkChecksum::Compute(fData, sizeof(fData));
        }
    }

private:
    typedef SkBenchmark INHERITED;
};

///////////////////////////////////////////////////////////////////////////////

static SkBenchmark* Fact0(void* p) { return new ComputeChecksumBench(p); }

static BenchRegistry gReg0(Fact0);