Recently there was an large rework to the STB single-file image_resize library (STBIR) bumping it to 2.0. While the v1 was really slow and merely usable if you needed to quickly get some code running, the 2.0 rewrite claims to be more considerate of performance by using SIMD. So lets put it to a test.
As references, I chose the moderately optimized C only implementation of Ogre3D and the highly optimized SIMD implementation in OpenCV.
Below you find time to scale a 1024x1024px byte image to 512x512px. All libraries were set to linear interpolation. The time is the accumulated time for 200 runs.
RGB | RGBA | |
Ogre3D 14.1.2 | 660 ms | 668 ms |
STBIR 2.01 | 632 ms | 690 ms |
OpenCV 4.8 | 245 ms | 254 ms |
For the RGBA test, STIBIR was set to the STBIR_4CHANNEL
pixel layout. All libraries were compiled with -O2 -msse
. Additionally OpenCV could dispatch AVX2 code. Enabling AVX2 with STBIR actually decreased performance.
Note that while STBIR has no performance advantage over a C only implementation for the simple resizing case, it offers some neat features if you want to handle SRGB data or non-premultiplied alpha.