Performance Question

Discussion in 'C++' started by BCC, Feb 26, 2004.

  1. BCC

    BCC Guest

    Why the huge drop in performance in STL from VC6.0 to VC7.1? Particularly
    with vector?

    The following code shows what I mean...

    Any thoughts?

    Thanks,
    B

    //Test the speed of operations on primitive arrays and vectors
    #pragma warning(disable: 4786)

    #include <vector>
    #include <time.h>
    #include <iostream>

    using namespace std;

    typedef vector<int> IntVec;

    int main(int argc, char* argv[])
    {
    clock_t start, finish;
    start = clock();
    const int dim1 = 1000;
    const int dim2 = 10000;

    int* matrix[dim1];
    for(int i = 0; i < dim1; i++)
    {
    matrix = new int[dim2];
    for(int j = 0; j < dim2; j++)
    matrix[j] = j;
    }

    finish = clock();
    cout << "Total time taken for " << dim1 << "x" << dim2;
    cout << " int array operations: ";
    cout << double(finish-start) / CLOCKS_PER_SEC << " seconds" << endl;
    for( i = 0; i < dim1; i++)
    {
    delete[] matrix;
    }

    start = clock();

    vector<IntVec> intvecs(dim1);
    for( i = 0; i < dim1; i++)
    {
    intvecs.resize(dim2);
    for(int j = 0; j < dim2; j++)
    intvecs[j] = j;
    }

    finish = clock();
    cout << "Total time taken for " << dim1 << "x" << dim2;
    cout << " int vector operations: ";
    cout << double(finish-start) / CLOCKS_PER_SEC << " seconds" << endl;

    return 0;
    }

    /**
    *
    ==========================

    output from VC6.0:

    Total time taken for 1000x10000 int array operations: 0.12 seconds
    Total time taken for 1000x10000 int vector operations: 0.14 seconds

    ==========================

    output from VC7.1:

    Total time taken for 1000x10000 int array operations: 0.12 seconds
    Total time taken for 1000x10000 int vector operations: 1.231 seconds
    ==========================

    */
    BCC, Feb 26, 2004
    #1
    1. Advertising

  2. "BCC" <> wrote in message
    news:m2v%b.30906$...
    > Why the huge drop in performance in STL from VC6.0 to VC7.1?

    Particularly
    > with vector?
    >
    > The following code shows what I mean...


    Here are my results:

    VC7.1:

    Total time taken for 1000x10000 int array operations: 0.062 seconds
    Total time taken for 1000x10000 int vector operations: 0.094 seconds

    VC6.5:

    Total time taken for 1000x10000 int array operations: 0.062 seconds
    Total time taken for 1000x10000 int vector operations: 0.235 seconds

    Are you sure you have optimizations turned on?

    Jonathan
    Jonathan Turkanis, Feb 26, 2004
    #2
    1. Advertising

  3. BCC

    Andre Kostur Guest

    "BCC" <> wrote in
    news:m2v%b.30906$:

    > Why the huge drop in performance in STL from VC6.0 to VC7.1?
    > Particularly with vector?
    >
    > The following code shows what I mean...
    >
    > Any thoughts?
    >
    > Thanks,
    > B
    >
    > //Test the speed of operations on primitive arrays and vectors
    > #pragma warning(disable: 4786)
    >
    > #include <vector>
    > #include <time.h>
    > #include <iostream>
    >
    > using namespace std;
    >
    > typedef vector<int> IntVec;
    >
    > int main(int argc, char* argv[])
    > {
    > clock_t start, finish;
    > start = clock();
    > const int dim1 = 1000;
    > const int dim2 = 10000;
    >
    > int* matrix[dim1];
    > for(int i = 0; i < dim1; i++)
    > {
    > matrix = new int[dim2];
    > for(int j = 0; j < dim2; j++)
    > matrix[j] = j;
    > }
    >
    > finish = clock();
    > cout << "Total time taken for " << dim1 << "x" << dim2;
    > cout << " int array operations: ";
    > cout << double(finish-start) / CLOCKS_PER_SEC << " seconds" << endl;
    > for( i = 0; i < dim1; i++)
    > {
    > delete[] matrix;
    > }
    >
    > start = clock();
    >
    > vector<IntVec> intvecs(dim1);
    > for( i = 0; i < dim1; i++)
    > {
    > intvecs.resize(dim2);
    > for(int j = 0; j < dim2; j++)
    > intvecs[j] = j;
    > }
    >
    > finish = clock();
    > cout << "Total time taken for " << dim1 << "x" << dim2;
    > cout << " int vector operations: ";
    > cout << double(finish-start) / CLOCKS_PER_SEC << " seconds" << endl;
    >
    > return 0;
    > }
    >
    > /**
    > *
    >==========================
    >
    > output from VC6.0:
    >
    > Total time taken for 1000x10000 int array operations: 0.12 seconds
    > Total time taken for 1000x10000 int vector operations: 0.14 seconds
    >
    >==========================
    >
    > output from VC7.1:
    >
    > Total time taken for 1000x10000 int array operations: 0.12 seconds
    > Total time taken for 1000x10000 int vector operations: 1.231 seconds
    >==========================
    >
    > */


    Well... 2 things
    1) This is compiler-specific, thus offtopic for comp.lang.c++
    2) Were these compiled in "release" mode and not "debug" mode?
    Andre Kostur, Feb 26, 2004
    #3
    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. Don Beal
    Replies:
    13
    Views:
    840
    Richard Grimes [MVP]
    Sep 29, 2003
  2. jm
    Replies:
    1
    Views:
    508
    alien2_51
    Dec 12, 2003
  3. Cris Rock

    Performance related Question.....

    Cris Rock, Feb 12, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    312
    Stefano Mostarda
    Feb 12, 2004
  4. cjl
    Replies:
    3
    Views:
    989
    John Nagle
    May 21, 2007
  5. Software Engineer
    Replies:
    0
    Views:
    329
    Software Engineer
    Jun 10, 2011
Loading...

Share This Page