Quote:Original post by Anonymous Poster
I really don't see how it is apples to oranges.. how is it not realworld? If i am constantly changing values in a fixed sized list that I index into, vector is TWICE as slow. It's much more realworld than most examples STL proponents use where they assign const values to the vector. Thats somethig that would just never happen in code.
The original poster asked what sort of an impact STL has. I gave one solid example. Yes it has helpful things, but it's at the expense of SPEED. I'm not saying STL isn't useful.. I'm just saying it's SLOWER.
STL's dependance on iterators adds overhead in the form of function calls, and reduced code cache coherency. I chose the vector, because it was an easy, reproducable, example.
How about you produce a resizeable array that beats std::vector. An array of known size would be more readily compared to boost::array or something like that.
[Edit]
for example, my own array class ( yes written this min )
template< class Type , int size >class Array{ Type array[size];public: Type &operator[]( int i ) { return array; }};
The test( only modified to include my class )
#define NUMELEMENTS 20000 #define NUMLOOPS 10000 int i, j, currloop; LARGE_INTEGER start_count, end_count, final_array_count, final_vector_count; //Start std::Vector benchmark printf("Profiling Array: "); QueryPerformanceCounter(&start_count); //Allocating vector once - giving capacity as an argument Array<char,NUMELEMENTS> testvector; for(currloop = 0; currloop < NUMLOOPS; currloop++) { for(i=0;i<NUMELEMENTS;i++) { testvector = (char)(i%256); } for(i=0;i<NUMELEMENTS;i++) { j = testvector; } } QueryPerformanceCounter(&end_count); final_vector_count.QuadPart = end_count.QuadPart - start_count.QuadPart; printf("%I64d\n",final_vector_count.QuadPart,final_vector_count.QuadPart); //Start Array benchmark printf("Profiling array: "); QueryPerformanceCounter(&start_count); char testarray[NUMELEMENTS]; //Allocating array once for(currloop = 0; currloop < NUMLOOPS; currloop++) { for(i=0;i<NUMELEMENTS;i++) { testarray = (char)(i%256); } for(i=0;i<NUMELEMENTS;i++) { j = testarray; } } QueryPerformanceCounter(&end_count); final_array_count.QuadPart = end_count.QuadPart - start_count.QuadPart; printf("%I64d\n",final_array_count.QuadPart,final_array_count.QuadPart); printf("arrays are %I64d times faster than Arrays\n",final_vector_count.QuadPart/final_array_count.QuadPart);
Output:
Profiling Array: 1541215Profiling array: 1554889arrays are 0 times faster than ArraysProfiling Array: 1559871Profiling array: 1557985arrays are 1 times faster than ArraysProfiling Array: 1595685Profiling array: 1574723arrays are 1 times faster than ArraysProfiling Array: 1582116Profiling array: 1569467Arrays are 1 times faster than ArraysProfiling Array: 1541563Profiling array: 1542605arrays are 0 times faster than ArraysProfiling Array: 1568356Profiling array: 1538190arrays are 1 times faster than ArraysProfiling Array: 1537563Profiling array: 1548769arrays are 0 times faster than ArraysProfiling Array: 1553744Profiling array: 1534552arrays are 1 times faster than ArraysProfiling Array: 1564541Profiling array: 1578182arrays are 0 times faster than ArraysProfiling Array: 1544573Profiling array: 1585902arrays are 0 times faster than ArraysProfiling Array: 1719074Profiling array: 1580499arrays are 1 times faster than Arrays
[/Edit]
[Edit2]
Running your original test 5 times:
Profiling std::vector: 2339557Profiling array: 1927296Arrays are 1 times faster than std::vectorProfiling std::vector: 2324930Profiling array: 1928806Arrays are 1 times faster than std::vectorProfiling std::vector: 2370096Profiling array: 1949948Arrays are 1 times faster than std::vectorProfiling std::vector: 2315778Profiling array: 1951442Arrays are 1 times faster than std::vectorProfiling std::vector: 2296300Profiling array: 1895905Arrays are 1 times faster than std::vector
Not by as much as yours...
Managed to only use -O2, not -O3 [embarrass]
Profiling std::vector: 2366109Profiling array: 2425419Arrays are 0 times faster than std::vectorProfiling std::vector: 2402442Profiling array: 2385358Arrays are 1 times faster than std::vectorProfiling std::vector: 2333141Profiling array: 2345274Arrays are 0 times faster than std::vectorProfiling std::vector: 2310996Profiling array: 2349740Arrays are 0 times faster than std::vectorProfiling std::vector: 2315365Profiling array: 2346695Arrays are 0 times faster than std::vectorProfiling std::vector: 2416623Profiling array: 2416476Arrays are 1 times faster than std::vectorProfiling std::vector: 2384026Profiling array: 2439520Arrays are 0 times faster than std::vectorProfiling std::vector: 2476950Profiling array: 2382431Arrays are 1 times faster than std::vectorProfiling std::vector: 2417932Profiling array: 2398543Arrays are 1 times faster than std::vectorProfiling std::vector: 2398195Profiling array: 2410084Arrays are 0 times faster than std::vector
And so on...
[/Edit2]
[Edited by - rip-off on April 20, 2006 1:21:36 PM]