source: trunk/src/testlib/qbenchmark_p.h@ 1168

Last change on this file since 1168 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 5.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtTest module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QBENCHMARK_P_H
43#define QBENCHMARK_P_H
44
45#include <stdlib.h>
46
47//
48// W A R N I N G
49// -------------
50//
51// This file is not part of the Qt API. It exists purely as an
52// implementation detail. This header file may change from version to
53// version without notice, or even be removed.
54//
55// We mean it.
56//
57
58#include <QtCore/qglobal.h>
59
60#if (defined(Q_OS_LINUX) || defined Q_OS_MAC) && !defined(QT_NO_PROCESS)
61#define QTESTLIB_USE_VALGRIND
62#else
63#undef QTESTLIB_USE_VALGRIND
64#endif
65
66#include "QtTest/private/qbenchmarkmeasurement_p.h"
67#include <QtCore/QMap>
68#include <QtTest/qtest_global.h>
69#ifdef QTESTLIB_USE_VALGRIND
70#include "QtTest/private/qbenchmarkvalgrind_p.h"
71#endif
72#include "QtTest/private/qbenchmarkevent_p.h"
73#include "QtTest/private/qbenchmarkmetric_p.h"
74
75QT_BEGIN_NAMESPACE
76
77struct QBenchmarkContext
78{
79 // None of the strings below are assumed to contain commas (see toString() below)
80 QString slotName;
81 QString tag; // from _data() function
82
83 int checkpointIndex;
84
85 QString toString() const
86 {
87 QString s = QString::fromLatin1("%1,%2,%3").arg(slotName).arg(tag).arg(checkpointIndex);
88 return s;
89 }
90
91 QBenchmarkContext() : checkpointIndex(-1) {}
92};
93
94class QBenchmarkResult
95{
96public:
97 QBenchmarkContext context;
98 qreal value;
99 int iterations;
100 QTest::QBenchmarkMetric metric;
101 bool setByMacro;
102 bool valid;
103
104 QBenchmarkResult()
105 : value(-1)
106 , iterations(-1)
107 , setByMacro(true)
108 , valid(false)
109 { }
110
111 QBenchmarkResult(
112 const QBenchmarkContext &context, const qreal value, const int iterations,
113 QTest::QBenchmarkMetric metric, bool setByMacro)
114 : context(context)
115 , value(value)
116 , iterations(iterations)
117 , metric(metric)
118 , setByMacro(setByMacro)
119 , valid(true)
120 { }
121
122 bool operator<(const QBenchmarkResult &other) const
123 {
124 return (value / iterations) < (other.value / other.iterations);
125 }
126};
127
128/*
129 The QBenchmarkGlobalData class stores global benchmark-related data.