0

How can I use the QTest::setBenchmarkResult method? I want an example of it. I have used this code:

QBENCHMARK{
    // Some code here ...
}

I want to catch the result of the benchmark and with a especific metric.

lumurillo
  • 31
  • 3
  • Use QTest::setBenchmarkResult() if you want to report benchmark results **without** using the QBENCHMARK macro. – Ilya Sep 30 '14 at 05:54
  • why do you need catch result of benchmark? It is printed in report (user readable form or xml). `setBenchmarkResult` is to report results when you are providing own version of benchmark code. – Marek R Sep 30 '14 at 08:10
  • How can I store in form or xml file, the results of the QBENCHMARK macro? – lumurillo Sep 30 '14 at 19:15

2 Answers2

0

Let's see example from the documentation:

void TestBenchmark::simple()
{
    QString str1 = QLatin1String("This is a test string");
    QString str2 = QLatin1String("This is a test string");

    QCOMPARE(str1.localeAwareCompare(str2), 0);

    QBENCHMARK {
        str1.localeAwareCompare(str2);
    }
}

Is it what you need?

Ilya
  • 4,583
  • 4
  • 26
  • 51
0

How can I use the QTest::setBenchmarkResult method?

You can use it to report a benchmark-metric result-value that you calculated yourself:

class CustomTimerBenchmark : public QObject
{
    Q_OBJECT

private slots:
    void BenchmarkNanosecondsWithCustomTimer()
    {
        MyCustomTimer myCustomTimer;
        timer.start();

        // here goes benchmarked code

        QTest::setBenchmarkResult(
            myCustomTimer.nanoseconds(), QTest::WalltimeNanoseconds);
        // ^^^^
        // This will treat BenchmarkNanosecondsWithCustomTimer
        // as benchmark that reports wall-time in nanoseconds
    }
};

I want to catch the result of the benchmark and with a especific metric.

You can not do it with QTest::setBenchmarkResult

AMA
  • 4,114
  • 18
  • 32