1
/*
2
 * Copyright (C) 2009 Holger Hans Peter Freyther
3
 * Copyright (C) 2010 Benjamin Poulain, Nokia
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Library General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Library General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Library General Public License
16
 * along with this library; see the file COPYING.LIB.  If not, write to
17
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 * Boston, MA 02110-1301, USA.
19
 */
20
21
#include "benchmarkcontroller.h"
22
23
AbstractBenchmarkController::AbstractBenchmarkController(const QString& testName, const QString& dataName, Benchmark* parent, int iterations)
24
    : m_benchmark(testName, dataName)
25
    , m_parent(parent)
26
    , m_currentIteration(0)
27
    , m_iterations(iterations)
28
    , m_aborted(false)
29
{
30
}
31
32
int AbstractBenchmarkController::defaultIterations = 11;
33
34
BenchmarkController::BenchmarkController(const QString& testName, const QString& dataName, Benchmark* parent)
35
    : AbstractBenchmarkController(testName, dataName, parent)
36
    , m_timed(false)
37
{
38
    m_timer.start();
39
}
40
41
void BenchmarkController::next()
42
{
43
    if (!m_timed && currentIteration() != 0)
44
        m_benchmark.addResult(timeElapsed());
45
    m_timed = false;
46
    AbstractBenchmarkController::next();
47
48
    m_timer.start();
49
}
50
51
long long BenchmarkController::timeElapsed() const
52
{
53
    return m_timer.elapsed();
54
}
55
56
void BenchmarkController::timeNow()
57
{
58
    if (currentIteration() != 0)
59
        m_benchmark.addResult(timeElapsed());
60
    m_timed = true;
61
}
62
63
SubSectionBenchmarkController::SubSectionBenchmarkController(const QString& testName, const QString& dataName, Benchmark *parent)
64
    : AbstractBenchmarkController(testName, dataName, parent)
65
    , m_running(false)
66
    , m_iterationTime(0)
67
{
68
}
69
70
void SubSectionBenchmarkController::next()
71
{
72
    stopSubMeasure();
73
    if (currentIteration() != 0)
74
        m_benchmark.addResult(m_iterationTime);
75
    AbstractBenchmarkController::next();
76
    m_iterationTime = 0;
77
}
78
79
void SubSectionBenchmarkController::startSubMeasure()
80
{
81
    m_running = true;
82
    m_timer.start();
83
}
84
85
void SubSectionBenchmarkController::stopSubMeasure()
86
{
87
    if (m_running) {
88
        m_running = false;
89
        m_iterationTime += m_timer.elapsed();
90
    }
91
}
92
93
TimePerFrameBenchmarkController::TimePerFrameBenchmarkController(const QString& testName, const QString& dataName, Benchmark* parent)
94
    : AbstractBenchmarkController(testName, dataName, parent)
95
    , m_frameCount(0)
96
{
97
    m_timer.start();
98
}
99
100
void TimePerFrameBenchmarkController::next()
101
{
102
    if (currentIteration() != 0)
103
        m_benchmark.addResult(m_timer.elapsed() / m_frameCount);
104
105
    m_frameCount = 0;
106
    AbstractBenchmarkController::next();
107
108
    m_timer.start();
109
}
110
111
void TimePerFrameBenchmarkController::newFrame()
112
{
113
    ++m_frameCount;
114
}