I was doing a quick performance test on a block of code
void ConvertToFloat( const std::vector< short >& audioBlock,
std::vec
First code writes to out[i]
which boils down to begin() + i
(ie. an addition). Second code uses push_back
, which probably writes immediately to a known pointer equivalent to end()
(ie. no addition). You could probably make the first run as fast as the second by using iterators rather than integer indexing.
Edit: also to clarify some other comments: the vector contains floats, and constructing a float is effectively a no-op (the same way declaring "float f;" does not emit code, only tells the compiler to save room for a float on the stack). So I think that any performance difference between resize()
and reserve()
for a vector of floats is not to do with construction.