Behavior of compilers.

Discussion in 'C++' started by Sharad Kala, Jul 28, 2004.

  1. Sharad Kala

    Sharad Kala Guest

    Hi,

    I want to know the behavior of modern C++ compilers for this short program.
    Basically this tells us the rate by which vector grows.

    #include <vector>
    #include <iostream>
    using namespace std;
    int main ()
    {
    vector<int> v;
    for (int i = 1; i <= 10; ++i)
    {
    v.push_back(i);
    cout << v.capacity() << " ";
    }
    }

    VC 7.0, 7.1 results - 1 2 3 4 6 6 9 9 9 13
    g++ 3.3.1 results - 1 2 4 4 8 8 8 8 16 16

    Can you share results of other major compiler vendors.

    Thanks,
    Sharad

    P.S. - I know this has to to do with whether the allocator uses
    first-fit/best-fit allocation strategy.
     
    Sharad Kala, Jul 28, 2004
    #1
    1. Advertising

  2. Sharad Kala

    Sharad Kala Guest

    "Sharad Kala" <> wrote in message
    news:...
    > Hi,
    >
    > I want to know the behavior of modern C++ compilers for this short

    program.
    > Basically this tells us the rate by which vector grows.
    >
    > #include <vector>
    > #include <iostream>
    > using namespace std;
    > int main ()
    > {
    > vector<int> v;
    > for (int i = 1; i <= 10; ++i)
    > {
    > v.push_back(i);
    > cout << v.capacity() << " ";
    > }
    > }
    >
    > VC 7.0, 7.1 results - 1 2 3 4 6 6 9 9 9 13
    > g++ 3.3.1 results - 1 2 4 4 8 8 8 8 16 16



    Some more results (of course obtained by varying the loop counter) -
    Borland 6 - 1 2 4 8 16 32 64 128 256 512 1024

    aCC: HP ANSI C++ B3910B A.03.39
    32 64 103 166 268 433 700 1132

    Sun's CC 5.0
    256 512 1024

    -Sharad
     
    Sharad Kala, Jul 28, 2004
    #2
    1. Advertising

  3. Sharad Kala wrote:
    >
    > Hi,
    >
    > I want to know the behavior of modern C++ compilers for this short program.
    > Basically this tells us the rate by which vector grows.
    >
    > #include <vector>
    > #include <iostream>
    > using namespace std;
    > int main ()
    > {
    > vector<int> v;
    > for (int i = 1; i <= 10; ++i)
    > {
    > v.push_back(i);
    > cout << v.capacity() << " ";
    > }
    > }
    >
    > VC 7.0, 7.1 results - 1 2 3 4 6 6 9 9 9 13
    > g++ 3.3.1 results - 1 2 4 4 8 8 8 8 16 16
    >
    > Can you share results of other major compiler vendors.
    >


    icc 8.0 (Intel C++ Compiler, tested with its original library
    on Linux; I heard it uses a combination of GNU and Dinkumware
    libraries): 1 3 3 9 9 9 9 9 9 27
    and so on beyond 10000000, i.e. power of 3.

    Denis
     
    Denis Remezov, Jul 28, 2004
    #3
  4. Sharad Kala

    Roshan Guest

    A long time back I read some reference to Don Knuth having researched into the
    issue of the optimal growth factor for "general cases".
    I believe it said his conclusion was that 1.5.
    I guess optimal means not being too wasteful (of memory) and at the same time
    something that doesnt require frequent
    resizing.

    From the results noted it looks like VC 7 (dinkumware really) is using 1.5 as its
    resize factor.

    I only vaguely recollect reading about Knuth's inference mentioned somewhere. So
    i could be wrong.

    -Roshan
     
    Roshan, Jul 29, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Julian Hershel

    Command line compilers

    Julian Hershel, Apr 29, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    504
    Julian Hershel
    Apr 30, 2004
  2. Replies:
    0
    Views:
    576
  3. Comparing compilers

    , Dec 5, 2005, in forum: VHDL
    Replies:
    4
    Views:
    731
    Mike Treseler
    Dec 6, 2005
  4. Mantorok Redgormor
    Replies:
    70
    Views:
    1,846
    Dan Pop
    Feb 17, 2004
  5. geletine

    commercial c compilers vs free c compilers

    geletine, Jul 2, 2006, in forum: C Programming
    Replies:
    33
    Views:
    1,364
Loading...

Share This Page