Absolute value functions performance

Absolute value functions performance

Recently, when I was working on a code that needed to compute float absolute value on a large array of numbers, I have to decide which function to use.
Here is simple test done on an array of 10000000 float numbers that shows that using custom simple template code is actually the fastest solution (except using SSE – see bottom of this page).

std::abs() 341 ms
fabsf()  322 ms
template 293 ms
SSE 7 ms

This test shows that std::abs function is actually the slowest one.

Test code (using Ogre for timings and log).


Using SSE:

1 thought on “Absolute value functions performance

Comments are closed.