Efficiency of Inline C ++

I am new to C ++, having a lot more C experience.

I am writing a program that will use a string class, and began to think about the effectiveness of the length () method.

I realized that I did not have a good answer to this question, and therefore it was interesting whether there was an answer somewhere to this and similar questions. Although I am more than capable of determining the execution time of my own code, I lose a little when it comes to the provided code, and therefore I believe that I can not accurately evaluate the effectiveness of my programs.

Is there any documentation in C ++ (online or in the "man" format) that contains information about the execution time of the provided code?

Edit: I'm interested in this at all, and not just the string :: length.

+5
source share
2 answers

Currently, the temporary complexity size()for all STL containers is unproven. There open the C ++ bug report for this.

This ISO C ++ standard states that STL containers must have size()constant complexity:

21.3 [lib.basic.string] / 2

The template for the basic_string class conforms to the sequence requirements as specified in (23.1.1). In addition, since the iterators supported by basic_string are random access iterators (24.1.5), basic_string meets the requirements of the Reversible container, as specified in (23.1).

23.1 [lib.container.requirements] / 5

  • Expression: a.size()
  • Difficulty: (Note A)

, '' ( A)

"should" ; , std::list, ( g++) O (N) std::list::size().

, , , (end() - begin()) (, ) O (1). , , operator-.

++ :

  • std::string::size() - O (1)
  • std::vector::size() - O (1)

, , : , , , , , end() .

+5

, , O (1).

, , - ++ - , ++ 03 . , . , , , here.

+5

All Articles