$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: me22 (me22.ca_at_[hidden])
Date: 2006-08-26 14:40:09
On 8/26/06, Janos Vegh <vegh.janos_at_[hidden]> wrote:
> I just used the default settings, no extra switches.
> BTW, you can edit and run the test program,
> maybe you can conclude something interesting through
> varying the optimization.
> Anyhow, the  difference between  simple  and  [] access
> is too big for a simple optimization, I think so.
>
main has to return int; Your code isn't legal C++.  Also, it seems
like you end up using memory in the vector after only reserving it,
not resizing it.
Your empty cycle time makes it obvious you're not even doing the most
rudimentary of optimizations.
Here's what I get in g++ (g++ (GCC) 4.1.1 (Gentoo 4.1.1)) after making
a few changes while using -O3 -DNDEBUG as arguments to the compiler
(though -DNDEBUG didn't make any signifigant difference):
Empty cycle
real    0m0.003s
user    0m0.000s
sys     0m0.000s
STL=1, SIMPLE=1, size=1000
real    0m1.357s
user    0m1.168s
sys     0m0.008s
STL=1, size=1000
real    0m1.337s
user    0m1.172s
sys     0m0.016s
STL=1, ITERATOR=1, size=1000
real    0m1.315s
user    0m1.172s
sys     0m0.012s
STL=1, AT=1, size=1000
real    0m1.357s
user    0m1.176s
sys     0m0.004s
I really don't see an issue here.
~ Scott McMurray
Code used:
#define STL 1
#define SIMPLE 0
#define ITERATOR 0
#define AT 1
#define EMPTY 0
#if STL
#include <vector>
#endif
    using namespace std;
#include <iostream>
#define ARR_SIZE 1000
#define CYCLES 1000000
int 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;
    #endif
    std::vector<long int> arr(ARR_SIZE);
    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
    }
}