Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ vectors question
    text
    copied!<p>Does anyone know how to speed up <code>boost::numeric::ublas::vector</code>?</p> <p>I am using <code>typedef ublas::vector&lt;float, ublas::bounded_array&lt;float, 3&gt; &gt; MYVECTOR3</code> and compare it's speed to <code>D3DXVECTOR3</code> on plain operations.</p> <p><em>The test look the following way:</em></p> <pre><code>#include &lt;d3dx9.h&gt; #pragma comment(lib, "d3dx9.lib") static const size_t kRuns = static_cast&lt;size_t&gt;(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 &lt; kRuns; ++i) { c = c + (a + b) * 0.5f; } } #include &lt;boost/numeric/ublas/vector.hpp&gt; TEST(Performance, CppStyleVectors) { typedef boost::numeric::ublas::vector&lt;float, boost::numeric::ublas::bounded_array&lt;float, 3&gt; &gt; 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 &lt; kRuns; ++i) { noalias(c) = c + (a + b) * 0.5f; } } </code></pre> <p><strong>And the results are the following:</strong></p> <pre><code>[----------] 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) </code></pre> <p>As you can see, plain C-style vector is about 20 times faster than one from <code>boost::numeric::ublas</code> even when using custom stack-based allocator. Does somebody have any idea on how I could speed it up? </p> <p><em>Maybe by writing a custom wrapper or something like that?</em></p> <p>Thank you</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload