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>
bb10
Marc Mutz 2023-11-15 09:54:42 +01:00
parent 6017695bfa
commit b08ba96fd0
3 changed files with 6 additions and 6 deletions

View File

@ -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;
}

View File

@ -28,8 +28,8 @@ public:
QBenchmarkIterationController();
QBenchmarkIterationController(RunMode runMode);
~QBenchmarkIterationController();
bool isDone();
void next();
bool isDone() const noexcept;
void next() noexcept;
int i;
};

View File

@ -149,7 +149,7 @@ public:
// low-level API:
namespace QTest
{
int iterationCount();
int iterationCount() noexcept;
void setIterationCountHint(int count);
void setIterationCount(int count);