Boost logo

Ublas :

From: Elliott Waldron (elliottwaldron_at_[hidden])
Date: 2007-02-23 16:01:48

I am a bit of a newbie to C++ programming. I work on both Win32 and Linux
platforms and have noticed sizable performance differences between compiling
under GCC and MSVC. In my code, I have localized the performance difference
to the sorting of vector containers. I wrote a simple test program to
measure the performance difference (appended at the end of this email).
The program times the sorting of std::vector's and ublas::vector's
populated with 10,000,000 random numbers.

Here are the results when compiled with MSVC 8:

sort of std::vector : 1.89 secs
sort of ublas::vector : 3.078 secs

Here are the results when compiled with GCC:

sort of std::vector : 2.734 secs
sort of ublas::vector : 17.828 secs

... pretty big difference - especially for the ublas vectors - any help in
sorting this out would be appreciated. BTW, not defining
much worse than they already are for GCC and has no effect for MSVC.

Thanks in advance.

Here are the MSVC 8 compiler options:
/EHsc /MD /Yu"stdafx.h" /Fp"Release\sort_test.pch" /Fo"Release\\"
/Fd"Release\vc80.pdb" /W3 /nologo /c /Wp64 /Zi /TP /errorReport:prompt

Here are the options I used with GCC
-O3 -malign-double -march=pentium4 -mfpmath=sse -ffast-math

And here is the test code:

//Standard STL includes

#include <boost/numeric/ublas/exception.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/detail/algorithm.hpp>

using namespace std;
namespace ublas = boost::numeric::ublas;

int main()

    int N = 10000000;
    vector<double> std_vec(N);
    ublas::vector<double> ubl_vec(N);
    time_t st;
    double e_time;

    //Generate Some Random Numbers
    generate(std_vec.begin(), std_vec.end(), rand);

    //Fill ublas::vector
    for(int i=0;i<std_vec.size();i++)
        ubl_vec[i] = std_vec[i];

    //Sort std::vector
    st = clock();
    e_time = double(clock()-st)/double(CLOCKS_PER_SEC);

    cout << "sort of std::vector : " << e_time << " secs " << endl;

    //Sort ublas::vector
    st = clock();
    e_time = double(clock()-st)/double(CLOCKS_PER_SEC);

    cout << "sort of ublas::vector : " << e_time << " secs " << endl;

    return 0;