diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-11-15 09:54:42 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-11-15 23:40:24 +0100 |
commit | b08ba96fd0eed8517a8a60c0d8d4064a7ab90498 (patch) | |
tree | edc3121052f03778bd98a53cf873cd7c66bb5dd4 | |
parent | 6017695bfa98d8d9a6e5977ec80aafa1a4d3ee4d (diff) |
QBENCHMARK: mark loop operations as noexcept
Tell the compiler that next() and isDone() cannot throw, so it doesn't
need to create exception handling code. This might yield more faithful
benchmark results for micro-benchmarks.
As a drive-by, mark isDone() as const, too.
Change-Id: Ifac3d9ee2f4df524e780fd07423e26bb5e87dab3
Reviewed-by: Jason McDonald <macadder1@gmail.com>
Reviewed-by: Isak Fyksen <isak.fyksen@qt.io>
-rw-r--r-- | src/testlib/qbenchmark.cpp | 6 | ||||
-rw-r--r-- | src/testlib/qbenchmark.h | 4 | ||||
-rw-r--r-- | src/testlib/qbenchmark_p.h | 2 |
3 files changed, 6 insertions, 6 deletions
diff --git a/src/testlib/qbenchmark.cpp b/src/testlib/qbenchmark.cpp index 4a8bd72ee9..af6ee5f7c6 100644 --- a/src/testlib/qbenchmark.cpp +++ b/src/testlib/qbenchmark.cpp @@ -167,7 +167,7 @@ QTest::QBenchmarkIterationController::~QBenchmarkIterationController() /*! \internal */ -bool QTest::QBenchmarkIterationController::isDone() +bool QTest::QBenchmarkIterationController::isDone() const noexcept { if (QBenchmarkTestMethodData::current->runOnce) return i > 0; @@ -176,14 +176,14 @@ bool QTest::QBenchmarkIterationController::isDone() /*! \internal */ -void QTest::QBenchmarkIterationController::next() +void QTest::QBenchmarkIterationController::next() noexcept { ++i; } /*! \internal */ -int QTest::iterationCount() +int QTest::iterationCount() noexcept { return QBenchmarkTestMethodData::current->iterationCount; } diff --git a/src/testlib/qbenchmark.h b/src/testlib/qbenchmark.h index 20c643b2c6..d0e8c78567 100644 --- a/src/testlib/qbenchmark.h +++ b/src/testlib/qbenchmark.h @@ -28,8 +28,8 @@ public: QBenchmarkIterationController(); QBenchmarkIterationController(RunMode runMode); ~QBenchmarkIterationController(); - bool isDone(); - void next(); + bool isDone() const noexcept; + void next() noexcept; int i; }; diff --git a/src/testlib/qbenchmark_p.h b/src/testlib/qbenchmark_p.h index 09379aac0f..902b092b16 100644 --- a/src/testlib/qbenchmark_p.h +++ b/src/testlib/qbenchmark_p.h @@ -149,7 +149,7 @@ public: // low-level API: namespace QTest { - int iterationCount(); + int iterationCount() noexcept; void setIterationCountHint(int count); void setIterationCount(int count); |