D
dgront
Have a look on a two pieces of C and C++ code, doing the same:
Version in C++:
class Point {
public:
double x;
double y;
double z;
};
vector<Point> v;
int n = 3000; // n is also the size of v
for(int j=1;j<n;j++) {
for(i=c.begin();i!=c.end();++i) {
i->x*=j;
i->y*=j;
i->z*=j;
}
for(i=c.begin();i!=c.end();++i) {
i->x/=j;
i->y/=j;
i->z/=j;
}
}
.... and in pure C
int *x,*y,*z; // Arrays have size n
for(int j=1;j<n;j++) {
for(int i=0;i!=n;++i) {
x*=j;
y*=j;
z*=j;
}
for(int i=0;i!=n;++i) {
x/=j;
y/=j;
z/=j;
}
}
The second one is 10 times faster (gcc version 3.2.2 20030222 (Red Hat
Linux 3.2.2-5), -O3)
Does it have to be so, or maybe I missed something?
Dominik Gront
Version in C++:
class Point {
public:
double x;
double y;
double z;
};
vector<Point> v;
int n = 3000; // n is also the size of v
for(int j=1;j<n;j++) {
for(i=c.begin();i!=c.end();++i) {
i->x*=j;
i->y*=j;
i->z*=j;
}
for(i=c.begin();i!=c.end();++i) {
i->x/=j;
i->y/=j;
i->z/=j;
}
}
.... and in pure C
int *x,*y,*z; // Arrays have size n
for(int j=1;j<n;j++) {
for(int i=0;i!=n;++i) {
x*=j;
y*=j;
z*=j;
}
for(int i=0;i!=n;++i) {
x/=j;
y/=j;
z/=j;
}
}
The second one is 10 times faster (gcc version 3.2.2 20030222 (Red Hat
Linux 3.2.2-5), -O3)
Does it have to be so, or maybe I missed something?
Dominik Gront