37% is a noticeable difference. I wonder what sort of optimization flags you played with in your code.
37% is a noticeable difference. I wonder what sort of optimization flags you played with in your code.
Yes, but if you read some of the other posts, I have a pretty old compiler, and the newer compilers are actually much closer (and vector is even faster in some of the examples).
Also, my code is the WORST possible scenario for vector, as it does so very little with the value it fetches from the vector.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I don't remember the entire thread and didn't read through it, but wasn't that a comparison between vector and a statically sized array?
We're discussing vector versus a dynamic array with new[]/delete[] here.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Doesn't stack memory work better with your CPU cache, and that's why arrays are faster that dynamic arrays? or is it just the calls to new/delete that slow down dynamic arrays?
In either case, calling vector::reserve() before you start inserting elements can reduce your new/delete calls to just 1.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
In the case of replacing new[]/delete[] with vector, you should be able to set an initial size in your vector constructor (just like you do when calling new[]). So there would be no need to call reserve or do any other tricks to reduce the memory allocations.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
Whether it slows anything down depends on what the array is holding. I guess I'm just talking about a simple replacement that involves using vector and getting rid of the need for delete. I'd consider reserve instead of the constructor to be a premature optimization in this thread.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}