I am trying to use valarray since it is much like MATLAB while operating vector and matrices. I first did some performance check and found that valarray cannot achieve the p
I suspect that the reason c = a*b is so much slower than performing the operations an element at a time is that the
template valarray operator*
(const valarray&, const valarray&);
operator must allocate memory to put the result into, then returns that by value.
Even if a "swaptimization" is used to perform the copy, that function still has the overhead of
valarrayvalarray (it's possible that this might be optimized away)valarrayvalarray as it is initialized or set with result valuesvalarray that gets replaced by the result