Skip to content

Commit

Permalink
Add comparison between QDateTime::fromMSecsSinceEpoch
Browse files Browse the repository at this point in the history
It is much faster to directly get the msecs in UTC rather then
first getting a local timestamp and converting it to UTC afterwards:

```
PASS   : BenchQDateTime::benchFromMSecsSinceEpoch()
RESULT : BenchQDateTime::benchFromMSecsSinceEpoch():
     0.0057 msecs per iteration (total: 94, iterations: 16384)
PASS   : BenchQDateTime::benchFromMSecsSinceEpochToUTC()
RESULT : BenchQDateTime::benchFromMSecsSinceEpochToUTC():
     0.0075 msecs per iteration (total: 62, iterations: 8192)
PASS   : BenchQDateTime::benchFromMSecsSinceEpochUTC()
RESULT : BenchQDateTime::benchFromMSecsSinceEpochUTC():
     0.000013 msecs per iteration (total: 57, iterations: 4194304)
```
  • Loading branch information
milianw committed Oct 17, 2023
1 parent 9d0a644 commit fe67264
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions bench_qdatetime/bench_qdatetime.cpp
Expand Up @@ -64,6 +64,39 @@ private slots:
}
}

Q_NEVER_INLINE void benchFromMSecsSinceEpoch()
{
qint64 msecs = 0;
clobber();

QBENCHMARK {
auto a = QDateTime::fromMSecsSinceEpoch(msecs);
escape(&a);
}
}

Q_NEVER_INLINE void benchFromMSecsSinceEpochToUTC()
{
qint64 msecs = 0;
clobber();

QBENCHMARK {
auto a = QDateTime::fromMSecsSinceEpoch(msecs).toUTC();
escape(&a);
}
}

Q_NEVER_INLINE void benchFromMSecsSinceEpochUTC()
{
qint64 msecs = 0;
clobber();

QBENCHMARK {
auto a = QDateTime::fromMSecsSinceEpoch(msecs, Qt::UTC);
escape(&a);
}
}

Q_NEVER_INLINE void benchQElapsedTimer()
{
QBENCHMARK {
Expand Down

0 comments on commit fe67264

Please sign in to comment.