Hello!
Does anyone know how to speed up boost::numeric::ublas::vector
?
I am using typedef ublas::vector<float, ublas::bounded_array<float, 3> > MYVECTOR3
and compare it's speed to D3DXVECTOR3
on plain operations.
The test look the following way:
#include <d3dx9.h>
#pragma comment(lib, "d3dx9.lib")
static const size_t kRuns = static_cast<size_t>(10e6);
TEST(Performance, CStyleVectors) {
D3DXVECTOR3 a(1.0f, 2.0f, 3.0f);
D3DXVECTOR3 b(2.0f, 3.0f, 1.0f);
D3DXVECTOR3 c(6.0f, 4.0f, 5.0f);
for (size_t i = 0; i < kRuns; ++i) {
c = c + (a + b) * 0.5f;
}
}
#include <boost/numeric/ublas/vector.hpp>
TEST(Performance, CppStyleVectors) {
typedef boost::numeric::ublas::vector<float,
boost::numeric::ublas::bounded_array<float, 3> > MYVECTOR3;
MYVECTOR3 a(3), b(3), c(3);
a[0] = 1.0f, a[1] = 2.0f, a[2] = 3.0f;
b[0] = 2.0f, b[1] = 3.0f, b[2] = 1.0f;
c[0] = 6.0f, c[1] = 4.0f, c[2] = 5.0f;
for (size_t i = 0; i < kRuns; ++i) {
noalias(c) = c + (a + b) * 0.5f;
}
}
And the results are the following:
[----------] 2 tests from Performance
[ RUN ] Performance.CStyleVectors
[ OK ] Performance.CStyleVectors (484 ms)
[ RUN ] Performance.CppStyleVectors
[ OK ] Performance.CppStyleVectors (9406 ms)
[----------] 2 tests from Performance (9890 ms total)
As you can see, plain C-style vector is about 20 times faster than one from boost::numeric::ublas
even when using custom stack-based allocator. Does somebody have any idea on how I could speed it up?
Maybe by writing a custom wrapper or something like that?
Thank you