| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtTest/private/qbenchmarktimemeasurers_p.h> |
| 5 | #include <QtTest/private/qbenchmark_p.h> |
| 6 | #include <QtTest/private/qbenchmarkmetric_p.h> |
| 7 | #include <QtTest/qbenchmark.h> |
| 8 | #include <qdebug.h> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | // QBenchmarkTimeMeasurer implementation |
| 13 | |
| 14 | void QBenchmarkTimeMeasurer::start() |
| 15 | { |
| 16 | time.start(); |
| 17 | } |
| 18 | |
| 19 | QList<QBenchmarkMeasurerBase::Measurement> QBenchmarkTimeMeasurer::stop() |
| 20 | { |
| 21 | return { { .value: qreal(time.elapsed()), .metric: QTest::WalltimeMilliseconds } }; |
| 22 | } |
| 23 | |
| 24 | bool QBenchmarkTimeMeasurer::isMeasurementAccepted(Measurement measurement) |
| 25 | { |
| 26 | return (measurement.value > 50); |
| 27 | } |
| 28 | |
| 29 | int QBenchmarkTimeMeasurer::adjustIterationCount(int suggestion) |
| 30 | { |
| 31 | return suggestion; |
| 32 | } |
| 33 | |
| 34 | bool QBenchmarkTimeMeasurer::needsWarmupIteration() |
| 35 | { |
| 36 | return true; |
| 37 | } |
| 38 | |
| 39 | int QBenchmarkTimeMeasurer::adjustMedianCount(int) |
| 40 | { |
| 41 | return 1; |
| 42 | } |
| 43 | |
| 44 | #ifdef HAVE_TICK_COUNTER // defined in 3rdparty/cycle/cycle_p.h |
| 45 | |
| 46 | void QBenchmarkTickMeasurer::start() |
| 47 | { |
| 48 | startTicks = getticks(); |
| 49 | } |
| 50 | |
| 51 | QList<QBenchmarkMeasurerBase::Measurement> QBenchmarkTickMeasurer::stop() |
| 52 | { |
| 53 | CycleCounterTicks now = getticks(); |
| 54 | return { { .value: qreal(elapsed(t1: now, t0: startTicks)), .metric: QTest::CPUTicks } }; |
| 55 | } |
| 56 | |
| 57 | bool QBenchmarkTickMeasurer::isMeasurementAccepted(QBenchmarkMeasurerBase::Measurement) |
| 58 | { |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | int QBenchmarkTickMeasurer::adjustIterationCount(int) |
| 63 | { |
| 64 | return 1; |
| 65 | } |
| 66 | |
| 67 | int QBenchmarkTickMeasurer::adjustMedianCount(int) |
| 68 | { |
| 69 | return 1; |
| 70 | } |
| 71 | |
| 72 | bool QBenchmarkTickMeasurer::needsWarmupIteration() |
| 73 | { |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | #endif |
| 78 | |
| 79 | |
| 80 | QT_END_NAMESPACE |
| 81 |
