|
Ublas : |
From: Karl Meerbergen (Karl.Meerbergen_at_[hidden])
Date: 2005-06-01 09:29:59
Stefan,
I have the impression that the ublas::vector has size 0 since you use
the default constructor.
I also think that vector::operator+=() creates a temporary to store the
data from the right-hand side. The right-hand side can be any
vector_expression. In order to avoid temporaries you could use
tmp.plus_assign( v ) and tmp.minus_assign( v ).
If this is the case, this might explain some loss of performance in
Christopher's tests.
Best,
Karl
Stefan Tarrant wrote:
>I don't find that at all, in fact I find it takes over 100x longer to run
>the test code for valarray as opposed to the ublas vector.
>
>I am also running VC++ 7.1, on a P4 3.2GHz. I have attached my test program.
>
>The output that I get is:
>
>15.046
>0.11
>Press any key to continue
>
>It takes about 15 sec to run with a valarray, and 0.11 sec with a ublas
>vector.
>
>Stefan
>
>-----Original Message-----
>From: ublas-bounces_at_[hidden]
>[mailto:ublas-bounces_at_[hidden]]On Behalf Of christopher diggins
>Sent: Tuesday, May 31, 2005 4:54 PM
>To: ublas_at_[hidden]
>Subject: [ublas] Performance concerns
>
>
>Vector addition/subtraction for ublas::vector takes 9x to 80x times as long
>to execute (for vectors from size 1024 to size 2) as std::valarray on my
>system (Visual C++ 7.1, release build, default optimizations) any reason for
>this?
>
>Here is the code:
>
> template<int iterations, class vector_T>
> void arithmetic_benchmark(vector_T& v)
> {
> {
> reporting_timer t;
> vector_T tmp = v;
> for (int i=0; i < iterations; i++) {
> tmp += v;
> tmp -= v;
> }
> }
> }
>
>Also even for simple element access the performance is several times slower.
>I can share my code if needed.
>
>Christopher Diggins
>http://www.cdiggins.com
>
>_______________________________________________
>ublas mailing list
>ublas_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/ublas
>
>
>------------------------------------------------------------------------
>
>#include <iostream>
>#include <valarray>
>#include <boost/timer.hpp>
>#include <boost/numeric/ublas/vector.hpp>
>
>const size_t size = 1024;
>const int iterations = 1000000;
>typedef double RealType;
>
>template<int iterations, class vector_t>
>void arithmetic_benchmark(vector_t& v)
>{
> {
> vector_t tmp = v;
> for ( int i = 0; i < iterations; ++i)
> {
> tmp += v;
> tmp -= v;
> }
> }
>}
>
>int main()
>{
> {
> std::valarray<RealType> v(size);
> boost::timer timer;
> arithmetic_benchmark<iterations>(v);
> std::cout << timer.elapsed() << std::endl;
> }
>
> {
> boost::numeric::ublas::vector<RealType> v;
> boost::timer timer;
> arithmetic_benchmark<iterations>(v);
> std::cout << timer.elapsed() << std::endl;
> }
>
> return 0;
>}
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>ublas mailing list
>ublas_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/ublas
>
>
-- ============================================== Look at our unique training program and Register on-line at http://www.fft.be/?id=35 ---------------------------------------------- Karl Meerbergen Free Field Technologies 16 place de l'Université B-1348 Louvain-la-Neuve - BELGIUM Company Phone: +32 10 45 12 26 Company Fax: +32 10 45 46 26 Mobile Phone: +32 474 26 66 59 Home Phone: +32 2 306 38 10 mailto:Karl.Meerbergen_at_[hidden] http://www.fft.be ==============================================