From b08ba96fd0eed8517a8a60c0d8d4064a7ab90498 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 15 Nov 2023 09:54:42 +0100 Subject: [PATCH] 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 Reviewed-by: Isak Fyksen --- src/testlib/qbenchmark.cpp | 6 +++--- src/testlib/qbenchmark.h | 4 ++-- 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);