PDA

View Full Version : Performance of QDataStream



drizzt
15th December 2009, 13:38
Hi all,

i would like to know if somebody knows about how fast QDataStream can write into a file?
( in MByte / second )




QFile file("test.txt");
QDataStream out(&file);
out.setByteOrder(QDataStream::LittleEndian);
file.open(QIODevice::WriteOnly);

QString s = "";

// 8mb string
for(int i = 0; i < 8388608; i++)
{
s.append("o");
}

QByteArray b = s.toLocal8Bit();

// writing 1GB data in the file
for(int i = 0; i < 256; i++)
{
out << b

}

in this test i get a datarate of ~90 MByte/sec.

Is there any way to improve the speed or has anybody information about QDataStream's speed?

Thanks

Lesiok
15th December 2009, 15:54
Try to use one of QDataStream::write methods.

drizzt
15th December 2009, 16:08
i tried that, it's the same speed...

wysota
15th December 2009, 17:31
in this test i get a datarate of ~90 MByte/sec.

Is there any way to improve the speed or has anybody information about QDataStream's speed?

This result is probably incorrect. You forget there is buffering involved. How do you measure the speed anyway?

By the way, 90MBps is 720Mbps which is almost one gigabit per second, I doubt your disk is that fast.

drizzt
15th December 2009, 20:30
i started a timer before i run the second for-loop and get the time bye t.elapsed() ...

so 1gb of data takes a time of ~11seconds.

wysota
15th December 2009, 22:55
so 1gb of data takes a time of ~11seconds.

Wrong. There is more data there as the byte array is serialized. And everything goes through a buffer which means you know exactly nothing about speed of QDataStream.

drizzt
16th December 2009, 08:35
Wrong. There is more data there as the byte array is serialized. And everything goes through a buffer which means you know exactly nothing about speed of QDataStream.


That was the question at the beginning of this question: how fast can i write data on disk?
I'm not the real expert, so i tried a lot of things.

what i can say now is, that after the second for-loop, in 11-12seconnds, i have a file on disk which is exackty 1GB.

You say thats wrong, what would you do?

wysota
16th December 2009, 08:58
That was the question at the beginning of this question: how fast can i write data on disk?
That depends on the disk.


what i can say now is, that after the second for-loop, in 11-12seconnds, i have a file on disk which is exackty 1GB.
You mean "1073741824 bytes" or "1GB"? If the latter then it's not 1GB, it's "about 1GB".


You say thats wrong, what would you do?
I wouldn't measure QDataStream performance. And if I really wanted to, then I wouldn't do it with a disk-based QIODevice underneath and I'd turn off all the buffering I could.

drizzt
16th December 2009, 09:22
1Gb = 1024 x 1024 x 1024 bytes yes :)

also what you want to say is: Qt can write data on disk as fast as my disk is?
If it works like it do in my example, its enough for my problem, which i have to solve.