This is a comparison between libspng and the reference implementation libpng.

Lines of code

libspng is 2.6 kLOC while libpng is ~10 kLOC without the encoding part or 18 kLOC in total.


The API is a lot simpler, decoding a PNG file takes about 30 lines. There are no row pointers or callback functions involved when reading from a buffer.

Error handling

All functions return zero on success and non-zero on error. libpng uses setjmp() for error handling, this makes it difficult to use from other languages such as C++.


libspng has a clear way to request a specific output format, with libpng the output format depends on whether you set alpha filler bits, it also has weird defaults such as not converting 16-bit PNG's to host endianness unless png_set_swap() is called.



libspng was compiled with GCC 6.3.0 with profile-guided optimizations and -O3. Debian's version of libpng is used for comparison, both libraries were linked against the packaged version zlib.

Time is measured with timespec_get(), each time is the average of 5 runs. These measurements include all library overhead and memory alllocations (initialization, output image buffer allocation, etc).

Decode performance - Intel Core i5-4670

spng average: 232181 microseconds
png average: 249347 microseconds
spng is 7.39% faster than libpng

spng average: 266426 microseconds
png average: 297699 microseconds
spng is 11.74% faster than libpng

spng average: 35779 microseconds
png average: 38171 microseconds
spng is 6.69% faster than libpng

spng average: 48445 microseconds
png average: 53191 microseconds
spng is 9.80% faster than libpng

spng average: 3499 microseconds
png average: 3691 microseconds
spng is 5.49% faster than libpng

spng average: 4100 microseconds
png average: 4536 microseconds
spng is 10.63% faster than libpng

results matching ""

    No results matching ""