Boost logo

Boost Users :

From: Alexis (alexismajordomo_at_[hidden])
Date: 2003-06-11 04:27:13


Hello all,

I am trying to use the boost::ublas library in my code to speed up
things, but I was a bit suspicious about the results. So I ran my own
tests, and I found that ublas is not as fast as the C implementation,
but is actually about twice slower (for my test, which are very
limited). Please find the source file below.
I am not very familiar with expression template. Am I doing something
wrong? Are the results specific to this test?

Thanks a lot.

Alexis

////////// CODE

#include <iostream>

#include "boost/numeric/interval.hpp"
#include "boost/numeric/interval/io.hpp"

#include "boost/numeric/ublas/config.hpp"
#include "boost/numeric/ublas/vector.hpp"
#include "boost/numeric/ublas/matrix.hpp"
#include "boost/numeric/ublas/vector_expression.hpp"
#include "boost/numeric/ublas/io.hpp"

#include "boost/timer.hpp"
#include "boost/progress.hpp"

namespace ublas = boost::numeric::ublas;

typedef int value_type;

#define N 14

typedef ublas::vector<value_type, ublas::bounded_array<value_type, N>
> uBlasVector;

#define K 100000000

int main(void)
{
     int k=0;

     // standard C
     value_type c1[N]={0, 1, 2}, c2[N]={3, 4, 5}, cres[N]={0, 4, 10};
     boost::timer timerC;
     for(k=0 ; k<K ; ++k)
     {
         for(int i=0 ; i<N ; ++i)
         {
             cres[i] = (c1[i] * c2[i]);
         }
     }
     std::cout << "c t=" << timerC.elapsed() << std::endl;

     // uBLAS
     uBlasVector v1(N), v2(N), res(N);

     boost::timer timerAssign3;
     for(k=0 ; k<K ; ++k)
     {
         res.assign(ublas::element_prod(v1,v2));
     }
     std::cout << "assign prod t=" << timerAssign3.elapsed() <<
std::endl;

     return 0;
}

[Non-text portions of this message have been removed]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net