aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/PictureBenchmark.cpp
blob: bb0d9fc3ea341b313ff8368054694cf1c066af9c (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * 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 "SkTypes.h"
#include "BenchTimer.h"
#include "PictureBenchmark.h"
#include "SkCanvas.h"
#include "SkPicture.h"
#include "SkString.h"
#include "picture_utils.h"

namespace sk_tools {

void PipePictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    fRenderer.init(pict);

    // We throw this away to remove first time effects (such as paging in this
    // program)
    fRenderer.render();

    BenchTimer timer = BenchTimer(NULL);
    timer.start();
    for (int i = 0; i < fRepeats; ++i) {
        fRenderer.render();
    }
    timer.end();

    fRenderer.end();

    SkDebugf("pipe: msecs = %6.2f", timer.fWall / fRepeats);
    if (fRenderer.isUsingGpuDevice()) {
        SkDebugf(" gmsecs = %6.2f", timer.fGpu / fRepeats);
    }
    SkDebugf("\n");
}

void RecordPictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    BenchTimer timer = BenchTimer(NULL);
    double wall_time = 0;

    for (int i = 0; i < fRepeats + 1; ++i) {
        SkPicture replayer;
        SkCanvas* recorder = replayer.beginRecording(pict->width(), pict->height());

        timer.start();
        recorder->drawPicture(*pict);
        timer.end();

        // We want to ignore first time effects
        if (i > 0) {
            wall_time += timer.fWall;
        }
    }

    SkDebugf("record: msecs = %6.5f\n", wall_time / fRepeats);
}

void SimplePictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    fRenderer.init(pict);

    // We throw this away to remove first time effects (such as paging in this
    // program)
    fRenderer.render();

    BenchTimer timer = BenchTimer(NULL);
    timer.start();
    for (int i = 0; i < fRepeats; ++i) {
        fRenderer.render();
    }
    timer.end();

    fRenderer.end();

    SkDebugf("simple: msecs = %6.2f", timer.fWall / fRepeats);
    if (fRenderer.isUsingGpuDevice()) {
        SkDebugf(" gmsecs = %6.2f", timer.fGpu / fRepeats);
    }
    SkDebugf("\n");
}

void TiledPictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    fRenderer.init(pict);

    // We throw this away to remove first time effects (such as paging in this
    // program)
    fRenderer.drawTiles();

    BenchTimer timer = BenchTimer(NULL);
    timer.start();
    for (int i = 0; i < fRepeats; ++i) {
        fRenderer.drawTiles();
    }
    timer.end();

    fRenderer.end();

    SkDebugf("%i_tiles_%ix%i: msecs = %6.2f", fRenderer.numTiles(), fRenderer.getTileWidth(),
            fRenderer.getTileHeight(), timer.fWall / fRepeats);
    if (fRenderer.isUsingGpuDevice()) {
        SkDebugf(" gmsecs = %6.2f", timer.fGpu / fRepeats);
    }
    SkDebugf("\n");
}

void UnflattenPictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (NULL == pict) {
        return;
    }

    BenchTimer timer = BenchTimer(NULL);
    double wall_time = 0;

    for (int i = 0; i < fRepeats + 1; ++i) {
        SkPicture replayer;
        SkCanvas* recorder = replayer.beginRecording(pict->width(), pict->height());

        recorder->drawPicture(*pict);

        timer.start();
        replayer.endRecording();
        timer.end();

        // We want to ignore first time effects
        if (i > 0) {
            wall_time += timer.fWall;
        }
    }

    SkDebugf("unflatten: msecs = %6.4f\n", wall_time / fRepeats);
}

}