C ++: How expensive isstream.tellp () is?

I want to call it in a tight cycle thousands of times per second. Is that an expensive call? I am using Windows Visual C ++.

+4
source share
2 answers

C ++ does not guarantee the performance (in seconds) of any particular parts of this standard library (although many containers and algorithms have complexity requirements).

This means that you are in the grip of your realization. The only reliable thing is to measure it and see if it is acceptable in your application.

+5
source

This is an old question, but I will still answer if there are other people who are looking for an answer.

So, we have a registration library that uses streams and tellp to determine file size. He called tellp for every magazine he made.

Thus, using the tellp 1 log line will take about 20 microseconds, depending on the machine. Without it, a magazine takes about 1 microsecond.

So yes, depending on your domain, this can be very expensive , or it may not matter at all.

ps the first optimization rule - do not optimize ..

+5
source

Source: https://habr.com/ru/post/1315624/


All Articles