Pergunta

I'm trying to figure out which is faster, as well as learn how to benchmark. Do you think this is an accurate way to test QFile VS ifstream?

http://ideone.com/ipkGh

Foi útil?

Solução

Speed and optimization are 2 important factors for every program. They are more programmer dependent than language or implementation dependent. Many times when we need optimizations we think that current language or implementation is not optimized. ifstream is a standard class in C++ and I think QFile uses that. The speed and the ratio you want to measure can be described and measured in a defined environment and it is better you describe the case you are facing.

Another important point, I can't understand why speed of a file operator class is important to you ?! Many file related operations can and should be done in the memory and traps to hard disks should stay minimum. So in an ideal situatuion I think there is no difference between ifstream , QFile or any slower framework for file access. For you and in general, both of these classes use native OS libraries. I think QFile uses ifstream. ifstream is a wrapper on native OS libraries and QFile is a thicker wrapper because of additional attributes. But I don't think this is very important when you want to use memory in an optimized and managed way.

Outras dicas

Well, i'd say they're both fast. You could always check the time that it takes to do the operations for both ifstream and QFile. But like someone said, if you use QFile you write less lines.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top