Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ STL

Name: Anonymous 2009-08-28 12:46

Is it faster to iterate through stl vector with the [] operator or an iterator?
I would think that the iterator is faster but I'm too lazy to test.

Name: Anonymous 2009-08-28 13:05

Accessing individual elements by their position index = constant time

Iterating over the elements in any order = linear time

Name: Anonymous 2009-08-28 13:20

Back to summer reading for CS101, please.

Name: Anonymous 2009-08-28 14:27

>>2
DOUBLE EXPERT SEPPLES PROGRAMMER AND /PROG/ POSTER

If this is the statistical /prog/-rider's knowledge of Sepples then no wonder they hate it.

Name: Haxus the Correct 2009-08-28 16:42

Name: Haxus the Correct 2009-08-28 16:47

Name: Haxus the Correct++ 2009-08-28 17:03

>>5 is the winner[1]

References:
1. http://www.cplusplus.com/reference/stl/vector/
   "Accessing individual elements by their position index (constant time)."
   "Iterating over the elements in any order (linear time)."

Name: Anonymous 2009-08-28 17:19

He said iterate, not access. Learn to read. I would say [] is faster because it can be optimized better?

Name: Anonymous 2009-08-28 17:22

>>8

Quoting myself. Actually both should end up as the same after optimizing.

Name: Haxus the Resigned 2009-08-28 17:36

Haxus the Resigned

Name: Sagesus the Unbumping 2009-08-28 18:26

Name: Anonymous 2009-08-28 19:43

>>5,2
Excellent!

Now that I know this, I can sort my vectors in O(N) time (probably faster)! Thank you, /YHBT/!

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List