Re: [eigen] About performance with 3-double vectors and self written library |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] About performance with 3-double vectors and self written library
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Tue, 2 Mar 2010 13:45:54 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=wYVFOz1QOeo5pEZr2v1/80PszbNsZhLHRuHW0m84XnU=; b=kBmrn6gY7g7l5Jg+rh9jNT4oUJuHM0Qvy3ik04x0UNUKepbHm6zJCvlvj9qtBx0caS dyglkfCceU9NFPlFDaR6gVq/zTWhztreLeFHJT5aiW6o8T84s7EovDF8yH0nQwxlpiBJ vAarsPaW2iczaVnG+NtmZO0dMAqUhILMAJ6Gw=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=Mvgkm4V5y6NULT77EXEyhUtrbmAse7+EuWGhTnnDN6rGP6rbhsX+nP1n+fLpnV09nw nMqB9ELtk9mNz5FH/lthA2wgH/Oe7uUMnN6OAytUG3KYJyXWA7BK4JRHSoztOS59UUAE YDINhUf4EcPlaYWKVJ8qBjWoJ2pP1LBAnjguA=
I played with your example a bit, but it's hard to extract anything
meaningful from it. Indeed, the performance difference is most
probably explained by the ability of the compiler to
reorganize/simplify these simple arithmetic operations. That explains
the difference between gcc 4.2 and 4.5.
Now in order to check this for sure, we have to study the asm, but
here it's not too easy because you're testing a bunch of operations at
once. So the first step would be to isolate the part of your benchmark
where the performance difference occurs.
Even though, if, as I suspect, it's just the compiler optimizing away
/ reorganizing arithmetic operations, then it's not a good benchmark
and so is not worth trying to make run faster.
Benoit
2010/3/2 William Oquendo <woquendo@xxxxxxxxx>:
> Dear all,
>
> I have written a small 3 dimensional - double - vector library, and I was
> expecting that eigen performance was better than my library. Unfortunately,
> that is not the case. I have run a test and, for g++ 4.2 I got aprox 12
> secons with eigen and aprox 6 seconds with my library. With g++ 4.5, I got
> 5.5 aprox for eigen and 7 aprox for my library.
>
> I wluld like to know if I am using eigen the wrong way and that is the cause
> of this c++4.2 performance penalty (I do not have access to g++ 4.5 on the
> production servers) or this is just an special case.
>
> I am attaching the code and copying it here:
>
> #include "vector3d.hh"
> #include <eigen2/Eigen/Core>
> #include <eigen2/Eigen/Geometry>
> USING_PART_OF_NAMESPACE_EIGEN
> #include <iostream>
> using namespace std;
>
> typedef Vector3D vec_t; // my library
> //typedef Vector3d vec_t; // Eigen
>
> const double STEPS = 1.0e4;
>
> int main(void)
> {
> double i;
> vec_t v1, v2;
> vec_t v3 = v2;
> vec_t v5;
> ///*
> for(double j = 0; j < STEPS; j++) {
> v3 = v2;
> // copy constructor
> for(i = 0; i < STEPS; i++) {
> vec_t v4 = v3;
> }
> // copy
> for(i = 0; i < STEPS; i++) {
> v3 = vec_t(i/0.34, i, i*i);
> }
> // accessing one element
> for(i = 0; i < STEPS; i++) {
> v3[1] = i;
> }
> // long airhmetic operations
> v1 = vec_t(1,2.2,3.4);
> v2 = vec_t(-2, 3, 3);
> for(i = 0; i < STEPS; i++) {
> v3 = vec_t(i/0.34, i, i*i);
> v5 = v1+v2-v3;
> }
> // scalar product
> double result;
> for(i = 0; i < STEPS; i++) {
> result = v3.dot(v5);
> }
> // cross product
> for(i = 0; i < STEPS; i++) {
> v5 = v1.cross(v2);
> }
> // complex operation
> for(i = 0; i < 10*STEPS; i++) {
> v5 = v1 + 2.0*v2 - v3/4.0 + (v3.cross(v2));
> }
> // normalize
> for(i = 0; i < STEPS; i++) {
> v3 = v5.normalized();
> }
> for(i = 0; i < STEPS; i++) {
> v5.normalize();
> }
> }
> //*/
> clog << v1 << endl;
> clog << v2 << endl;
> clog << v3 << endl;
> clog << v5 << endl;
> return 0;
> }
>
>
>
> Best regards / Cordialmente,
>
> --
> William Oquendo
> Phd Candidate
> Simulation Of Physical Systems Group
> National University of Colombia
> Linux User # 321481
> *********************
> Este correo puede carecer de tildes o eñes ya que el teclado no contiene
> estos caracteres. Presento excusas por eso.
>
> *********************
>
>
#include<cstdio>
#include <eigen2/Eigen/Core>
#include <eigen2/Eigen/Geometry>
USING_PART_OF_NAMESPACE_EIGEN
#include <iostream>
using namespace std;
#include "vector3d.hh"
#ifdef YOURLIB
typedef Vector3D vec_t; // my library
#else
typedef Vector3d vec_t; // Eigen
#endif
const double STEPS = 1.0e4;
int main(void)
{
double i;
vec_t v1, v2;
vec_t v3 = v2;
vec_t v5;
///*
for(double j = 0; j < STEPS; j++) {
v3 = v2;
// copy constructor
for(i = 0; i < STEPS; i++) {
vec_t v4 = v3;
}
// copy
for(i = 0; i < STEPS; i++) {
v3 = vec_t(i/0.34, i, i*i);
}
// accessing one element
for(i = 0; i < STEPS; i++) {
v3[1] = i;
}
// long airhmetic operations
v1 = vec_t(1,2.2,3.4);
v2 = vec_t(-2, 3, 3);
for(i = 0; i < STEPS; i++) {
v3 = vec_t(i/0.34, i, i*i);
v5 = v1+v2-v3;
}
// scalar product
double result;
for(i = 0; i < STEPS; i++) {
result = v3.dot(v5);
}
// cross product
for(i = 0; i < STEPS; i++) {
v5 = v1.cross(v2);
}
// complex operation
for(i = 0; i < 10*STEPS; i++) {
v5 = v1 + 2.0*v2 - v3/4.0 + (v3.cross(v2));
}
// normalize
for(i = 0; i < STEPS; i++) {
v3 = v5.normalized();
}
for(i = 0; i < STEPS; i++) {
v5.normalize();
}
}
//*/
clog << v1 << endl;
clog << v2 << endl;
clog << v3 << endl;
clog << v5 << endl;
return 0;
}