aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/PictureBenchmark.cpp
blob: a9449a1da09043fcf5e78a56e3dbdd34f770ee59 (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
/*
 * 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 (pict == NULL) {
        return;
    }

    renderer.init(pict);

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

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

    renderer.end();

    SkDebugf("pipe: msecs = %6.2f\n", timer.fWall / fRepeats);
}

void RecordPictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (pict == NULL) {
        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 (pict == NULL) {
        return;
    }

    renderer.init(pict);

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

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

    renderer.end();

    printf("simple: msecs = %6.2f\n", timer.fWall / fRepeats);
}

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

    renderer.init(pict);

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

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

    renderer.end();

    SkDebugf("%i_tiles_%ix%i: msecs = %6.2f\n", renderer.numTiles(), renderer.getTileWidth(),
            renderer.getTileHeight(), timer.fWall / fRepeats);
}

void UnflattenPictureBenchmark::run(SkPicture* pict) {
    SkASSERT(pict);
    if (pict == NULL) {
        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);
}

}