b0fa0bc by Benjamin Poulain at 2010-03-09 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
a7fe32c by Benjamin Poulain at 2010-03-09 23
AbstractBenchmarkController::AbstractBenchmarkController(const QString& testName, const QString& dataName, Benchmark* parent, int iterations)
24
    : m_benchmark(testName, dataName)
b0fa0bc by Benjamin Poulain at 2010-03-09 25
    , m_parent(parent)
a7fe32c by Benjamin Poulain at 2010-03-09 26
    , m_currentIteration(0)
27
    , m_iterations(iterations)
5e2cdea by Benjamin Poulain at 2010-08-11 28
    , m_aborted(false)
b0fa0bc by Benjamin Poulain at 2010-03-09 29
{
30
}
31
a7fe32c by Benjamin Poulain at 2010-03-09 32
int AbstractBenchmarkController::defaultIterations = 11;
33
bb9d065 by Benjamin Poulain at 2010-07-05 34
BenchmarkController::BenchmarkController(const QString& testName, const QString& dataName, Benchmark* parent)
a7fe32c by Benjamin Poulain at 2010-03-09 35
    : AbstractBenchmarkController(testName, dataName, parent)
36
    , m_timed(false)
b0fa0bc by Benjamin Poulain at 2010-03-09 37
{
e9492ec by Benjamin Poulain at 2010-07-05 38
    m_timer.start();
b0fa0bc by Benjamin Poulain at 2010-03-09 39
}
40
41
void BenchmarkController::next()
42
{
a7fe32c by Benjamin Poulain at 2010-03-09 43
    if (!m_timed && currentIteration() != 0)
b0fa0bc by Benjamin Poulain at 2010-03-09 44
        m_benchmark.addResult(timeElapsed());
45
    m_timed = false;
a7fe32c by Benjamin Poulain at 2010-03-09 46
    AbstractBenchmarkController::next();
b0fa0bc by Benjamin Poulain at 2010-03-09 47
e9492ec by Benjamin Poulain at 2010-07-05 48
    m_timer.start();
b0fa0bc by Benjamin Poulain at 2010-03-09 49
}
50
51
long long BenchmarkController::timeElapsed() const
52
{
e9492ec by Benjamin Poulain at 2010-07-05 53
    return m_timer.elapsed();
b0fa0bc by Benjamin Poulain at 2010-03-09 54
}
55
56
void BenchmarkController::timeNow()
57
{
a7fe32c by Benjamin Poulain at 2010-03-09 58
    if (currentIteration() != 0)
b0fa0bc by Benjamin Poulain at 2010-03-09 59
        m_benchmark.addResult(timeElapsed());
60
    m_timed = true;
61
}
62
a7fe32c by Benjamin Poulain at 2010-03-09 63
SubSectionBenchmarkController::SubSectionBenchmarkController(const QString& testName, const QString& dataName, Benchmark *parent)
64
    : AbstractBenchmarkController(testName, dataName, parent)
b0fa0bc by Benjamin Poulain at 2010-03-09 65
    , m_running(false)
66
    , m_iterationTime(0)
67
{
68
}
69
70
void SubSectionBenchmarkController::next()
71
{
72
    stopSubMeasure();
a7fe32c by Benjamin Poulain at 2010-03-09 73
    if (currentIteration() != 0)
b0fa0bc by Benjamin Poulain at 2010-03-09 74
        m_benchmark.addResult(m_iterationTime);
a7fe32c by Benjamin Poulain at 2010-03-09 75
    AbstractBenchmarkController::next();
b0fa0bc by Benjamin Poulain at 2010-03-09 76
    m_iterationTime = 0;
77
}
78
79
void SubSectionBenchmarkController::startSubMeasure()
80
{
81
    m_running = true;
e9492ec by Benjamin Poulain at 2010-07-05 82
    m_timer.start();
b0fa0bc by Benjamin Poulain at 2010-03-09 83
}
84
85
void SubSectionBenchmarkController::stopSubMeasure()
86
{
c5c0a5e by Benjamin Poulain at 2010-03-09 87
    if (m_running) {
b0fa0bc by Benjamin Poulain at 2010-03-09 88
        m_running = false;
e9492ec by Benjamin Poulain at 2010-07-05 89
        m_iterationTime += m_timer.elapsed();
b0fa0bc by Benjamin Poulain at 2010-03-09 90
    }
91
}
c5c0a5e by Benjamin Poulain at 2010-03-09 92
93
TimePerFrameBenchmarkController::TimePerFrameBenchmarkController(const QString& testName, const QString& dataName, Benchmark* parent)
94
    : AbstractBenchmarkController(testName, dataName, parent)
95
    , m_frameCount(0)
96
{
e9492ec by Benjamin Poulain at 2010-07-05 97
    m_timer.start();
c5c0a5e by Benjamin Poulain at 2010-03-09 98
}
99
100
void TimePerFrameBenchmarkController::next()
101
{
bb9d065 by Benjamin Poulain at 2010-07-05 102
    if (currentIteration() != 0)
e9492ec by Benjamin Poulain at 2010-07-05 103
        m_benchmark.addResult(m_timer.elapsed() / m_frameCount);
bb9d065 by Benjamin Poulain at 2010-07-05 104
c5c0a5e by Benjamin Poulain at 2010-03-09 105
    m_frameCount = 0;
106
    AbstractBenchmarkController::next();
107
e9492ec by Benjamin Poulain at 2010-07-05 108
    m_timer.start();
c5c0a5e by Benjamin Poulain at 2010-03-09 109
}
110
111
void TimePerFrameBenchmarkController::newFrame()
112
{
113
    ++m_frameCount;
114
}
115