Boost logo

Boost Users :

From: Stefan Tarrant (stefan.tarrant_at_[hidden])
Date: 2006-08-28 14:47:37


Hi,

I profiled some example code (not yours) using AQTime. Here is a screen
shot of the results. You can see that in the inner loop I am accessing
the elements using the [] operator, the array and the vector operations
perform almost identically, accessing with at() is quite a bit more
expensive.

Stefan

Janos Vegh wrote:
> Hi,
>
> I was interested in the efficiacy of std::vector.
> Using the test program below, I receive the following results.
> The "simple" handling is equivalent with the C array access.
> The [] and iterator access time of the vector element
> is an order of magnitude worse, than that of the simple access.
> This is not because of index limit control, it is done by at()
> and its use increases that access time by a factor of three.
> What is going on in the background here, that the implementation
> is so ineffective?
> ( I did my tests with WinXP/cygwin/g++/time,
> using different setting of the #define-s at the beginning)
> Shall I expect similar ineffectivity with the other STL objects?
>
> Regards
>
> Janos
>
>
> Empty cycle
> real 0m2.173s
> user 0m1.892s
> sys 0m0.080s
>
> STL=1, SIMPLE=1, size=0
> real 0m4.917s
> user 0m4.646s
> sys 0m0.070s
>
> STL=1, size=0
> real 0m33.939s
> user 0m33.658s
> sys 0m0.090s
>
> STL=1, ITERATOR=1, size=1000
> real 0m34.059s
> user 0m33.688s
> sys 0m0.100s
>
> STL=1, AT=1, size=1000
> real 1m22.769s
> user 1m22.368s
> sys 0m0.090s
>
> #define STL 1
> #define SIMPLE 0
> #define ITERATOR 1
> #define AT 0
> #define EMPTY 1
> #if STL
> #include <vector>
> #endif
> using namespace std;
> #include <iostream>
> #define ARR_SIZE 1000
> #define CYCLES 1000000
> main (int argc, char** argv)
> {
> long int i,j,*P;
> #if EMPTY
> cout << "Empty cycle";
> #else
> #if STL
> #if ITERATOR || AT
> std::vector<long int>::iterator pos;
> std::vector<long int> arr(ARR_SIZE);
> #else
> std::vector <long int> arr;
> arr.reserve(ARR_SIZE);
> #endif
>
> cout << "STL=1";
> #if SIMPLE
> cout << ", SIMPLE=1";
> #endif
> #if ITERATOR
> cout << ", ITERATOR=1";
> #endif
> #if AT
> cout << ", AT=1";
> #endif
> cout << ", size=" << arr.size();
> #else
> long int *arr;
> arr = new long int[ARR_SIZE];
> cout << "STL=0";
> #endif
> #endif
> cout << endl;
> #if SIMPLE && STL
> P = &arr[0];
> #endif
> for(j=0;j<CYCLES; j++)
> {
> #if STL && ITERATOR && !EMPTY
> i = 0;
> for(pos=arr.begin(); pos < arr.end(); ++pos)
> {
> *pos = i;
> }
> #else
> for(i=0; i<ARR_SIZE; i++)
> {
> #if !EMPTY
> #if SIMPLE && STL
> P[i] = i;
> #elif STL && AT
> arr.at(i) = i;
> #else
> arr[i] = i;
> #endif
> #endif
> }
> #endif
> }
> exit(0);
> }
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

-- 
Stefan Tarrant
Senior Project Engineer
C-CORE
Captain Robert A. Bartlett Building
Morrissey Road
St. John's, NL
Canada  A1B 3X5
Celebrating 30 years of Providing Innovative Engineering Solutions,
1975-2005.
Tel:               709 737-8372
General Fax:       709 737-4706
http://www.c-core.ca
---------------------------------------------------------------------
This communication (including all attachments) is intended solely for 
the use of the person or persons to whom it is addressed and should be 
treated as a confidential C-CORE communication.  If you are not the 
intended recipient, any use, distribution, printing, or copying of this 
email is strictly prohibited.  If you received this email in error, 
please immediately delete it from your system and notify the originator. 
  Your cooperation is appreciated.


Prof1.jpg

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net