Re: Big performance problem with QDateTime

Robert Krawitz <rlk-FrUbXkNCsVf2fBVCVOL8/[email protected]> Sun, 20 Sep 2020 16:52:24 -0400
Newsgroups gmane.comp.kde.kimdaba
Message-ID <[email protected]>
On 9/20/20 12:05 PM, Tobias Leupold wrote:
>> Well, we'll see.  It's not the first bug that's been filed on this, and their response has been
>> "comparing dates Is Complicated (tm)".
> 
> Yeah, same e. g. for https://bugreports.qt.io/browse/QTBUG-77721 ;-)

I created a nice, simple test case (attached).

_______________________________________________
KPhotoAlbum mailing list
[email protected]
https://mail.kdab.com/mailman/listinfo/kphotoalbum
datetimetest.cpp (text/x-c++src, 1 KB)
#include <QDateTime>
#include <QMap>
#include <QList>
#include <QListIterator>
#include <QDebug>

qint64 start = 1000000000;	// Start time is arbitrary

extern void
insertDatesIntoMap(const QList<QDateTime> &dlist)
{
  QListIterator<QDateTime> ilist(dlist);
  QMap<QDateTime, qint64> datemap;
  qInfo() << "Inserting into map at" << QDateTime::currentDateTime();
  while (ilist.hasNext())
    datemap.insert(ilist.next(), start++);
  qInfo() << "Done inserting into map at" << QDateTime::currentDateTime();
}

extern void
buildList(QList<QDateTime> &dlist, int count)
{
  qInfo() << "Building list at" << QDateTime::currentDateTime();
  for (int i = 0; i < count; i++)
    {
      QDateTime date;
      date.setSecsSinceEpoch(start);
      start += 3600;
      dlist += date;
    }
  qInfo() << "Done building list at" << QDateTime::currentDateTime();
}

int
main(int argc, char **argv)
{
  int count = 400000;
  if (argc > 1)
    count = atoi(argv[1]);
  QList<QDateTime> dlist;
  buildList(dlist, count);
  insertDatesIntoMap(dlist);
}