Velocity Reviews > C++ > Performance Question

# Performance Question

BCC
Guest
Posts: n/a

 02-26-2004
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[i] = new int[dim2];
for(int j = 0; j < dim2; j++)
matrix[i][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[i];
}

start = clock();

vector<IntVec> intvecs(dim1);
for( i = 0; i < dim1; i++)
{
intvecs[i].resize(dim2);
for(int j = 0; j < dim2; j++)
intvecs[i][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
==========================

*/

Jonathan Turkanis
Guest
Posts: n/a

 02-26-2004
"BCC" <(E-Mail Removed)> wrote in message
news:m2v%b.30906\$(E-Mail Removed) m...
> 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

Andre Kostur
Guest
Posts: n/a

 02-26-2004
"BCC" <(E-Mail Removed)> wrote in
news:m2v%b.30906\$(E-Mail Removed) m:

> 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[i] = new int[dim2];
> for(int j = 0; j < dim2; j++)
> matrix[i][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[i];
> }
>
> start = clock();
>
> vector<IntVec> intvecs(dim1);
> for( i = 0; i < dim1; i++)
> {
> intvecs[i].resize(dim2);
> for(int j = 0; j < dim2; j++)
> intvecs[i][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?

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Software Engineer Javascript 0 06-10-2011 02:18 AM cjl Python 3 05-21-2007 02:49 AM Cris Rock ASP .Net 1 02-12-2004 10:47 AM jm ASP .Net 1 12-12-2003 11:14 PM Don Beal ASP .Net 13 09-29-2003 03:46 PM

Advertisments