[IPOL discuss] RGB->gray conversion and speed comparison
Miguel Colom
Miguel.Colom at cmla.ens-cachan.fr
Fri Jul 29 12:45:03 CEST 2011
> The results for the two main compilers gcc and icc on my machine are
> in the attached file report.txt. My interpretation is that integer
> code is faster than floating-point code. The difference is even more
> clear when you measure the cost of many identical operations
> (BLOCK_SIZE > 1 in bench.c), and I think this means CPU pipelining is
> more efficient for integer than for floats.
In my opinion, we should take into account that the color to gray
conversion operation usually is done just once before applying the
algorithm.
Therefore, saving a few CPU clocks in this operation is irrelevant.
Moreover, using the round function of the math library with floating point
data types has some advantages:
- The result is quite exact when performed before the integer truncation.
- The code is easy to understand.
- The code is portable. There's no reason why the bit shift operations
used to divide/multiply could be applicable in all architectures.
- Errors in the implementation can be easily noticed. If coded with bin
shift operations, no one would have ever found the bug Nicolas sent to the
libPNG mailing list today.
- No speed-up is critical in the conversion, because it's done just once.
Saving a few CPU clocks in this step is irrelevant.
More information about the discuss
mailing list