Reading from a file realized with Qt/MinGW is slower than in Delphi 7
-
wrote on 22 Jul 2010, 09:53 last edited by
I need to read a simple structured file.
This is an algorithm
@
bool Reader::readTo(void *dest)
{
if (!file->open(QIODevice::ReadOnly) || !dest) return false;
QTextStream in(file);
Data *data = (Data *) dest;QString line = "";
QString datetime;
Point *point;
int size = 0;
data->clear();
while ((!in.atEnd()) || !line.contains("//STOP", Qt::CaseInsensitive)){
line = in.readLine();
size += line.size();
int index = line.indexOf('[');
if (index != -1) {
datetime = line.mid(0, index);
point = new Point();
point->date = QDateTime::fromString(datetime, "<yy/MM/dd>(hh:mm:ss:z)");
point->date = point->date.addYears(100);
QStringList data = line.mid(index + 1, line.count() - index - 2).split(" ");for (int i = 0; i < count; i++)
{
point.data.append(data.at(i).toInt());
}
data->append(*point);
delete point;
}
}
file->close();
return true;
}
@So, that algorithm is 20% slower than analogue in Delphi. I noticed that the most expensive operation is data.at(i).toInt(). Maybe I compiled Qt wrong? Any ideas?
-
wrote on 22 Jul 2010, 10:11 last edited by
Could you please mark up your code as code? Thanks!
-
wrote on 22 Jul 2010, 11:38 last edited by
Sorry about code, it is my first post, but what can be wrong with algorithm?
this is example of the file:
<10/03/10>(06:11:24:00)[1245 1245 1248 1237 1259 2107 2166 2125 1261 2241]
thanks for help
-
wrote on 22 Jul 2010, 15:10 last edited by
I think this becouse you using QTextStream and QString classes. They convert string to Unicode each time when you read from file. Try use QFile and QByteArray instead.
-
wrote on 23 Jul 2010, 19:32 last edited by
Yes, the problem was in converting to Unicode. Thank you, Sabrog.
1/5