Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPEG/PNG I/O performance #183

Open
s-trinh opened this issue Nov 17, 2021 · 2 comments
Open

JPEG/PNG I/O performance #183

s-trinh opened this issue Nov 17, 2021 · 2 comments

Comments

@s-trinh
Copy link
Contributor

s-trinh commented Nov 17, 2021

I am interested into having JPEG+PNG read/write capabilities without the need to install third party libraries such as libjpeg, libpng or OpenCV, and for x86 and ARM architectures.

Your recent additions of SimdImageLoadFromFile, SimdImageLoadFromMemory, ... are thus very interesting 👍

I have performed a quick benchmark:

  • JPEG loading:
-------------------------------------------------------------------------------
Benchmark JPEG image loading
  Klimt (558x560)
...............................................................................

benchmark name                                  samples       iterations    estimated
                                                mean          low mean      high mean
                                                std dev       low std dev   high std dev
-------------------------------------------------------------------------------
libjpeg backend                                         100            1    405.63 ms 
                                                 3.56186 ms   3.53802 ms   3.64835 ms 
                                                 205.099 us    51.976 us   469.633 us 
                                                                                      
OpenCV backend                                          100            1   165.626 ms 
                                                 1.65111 ms   1.64003 ms   1.66855 ms 
                                                  69.505 us    49.168 us    96.232 us 
                                                                                      
simd backend                                            100            1   390.039 ms 
                                                   3.947 ms   3.93922 ms   3.95504 ms 
                                                  40.207 us    35.241 us    47.092 us 
                                                                                      
stb backend                                             100            1   213.652 ms 
                                                 2.14247 ms   2.13979 ms   2.14649 ms 
                                                  16.566 us    12.111 us    22.554 us 
                                                                                      

-------------------------------------------------------------------------------
Benchmark JPEG image loading
  VGA (640x480)
...............................................................................

benchmark name                                  samples       iterations    estimated
                                                mean          low mean      high mean
                                                std dev       low std dev   high std dev
-------------------------------------------------------------------------------
libjpeg backend                                         100            1   447.168 ms 
                                                 4.43511 ms   4.39221 ms   4.51372 ms 
                                                 289.083 us   180.912 us   465.943 us 
                                                                                      
OpenCV backend                                          100            1   240.883 ms 
                                                  2.4037 ms   2.39479 ms    2.4167 ms 
                                                  54.347 us    39.874 us    80.909 us 
                                                                                      
simd backend                                            100            1   458.557 ms 
                                                 4.57222 ms   4.55966 ms   4.58537 ms 
                                                  65.412 us    56.569 us    78.949 us 
                                                                                      
stb backend                                             100            1   379.759 ms 
                                                 3.83431 ms   3.81595 ms   3.87169 ms 
                                                  127.62 us    73.292 us    222.63 us 
                                                                                      

-------------------------------------------------------------------------------
Benchmark JPEG image loading
  HD (1920x1080)
...............................................................................

benchmark name                                  samples       iterations    estimated
                                                mean          low mean      high mean
                                                std dev       low std dev   high std dev
-------------------------------------------------------------------------------
libjpeg backend                                         100            1     2.6468 s 
                                                 26.5927 ms   26.5011 ms   26.7623 ms 
                                                 615.562 us   397.935 us   1.00658 ms 
                                                                                      
OpenCV backend                                          100            1     1.4219 s 
                                                 14.1674 ms   14.1379 ms   14.1968 ms 
                                                 150.364 us   134.205 us    170.94 us 
                                                                                      
simd backend                                            100            1    2.84804 s 
                                                 28.6468 ms   28.6021 ms   28.6962 ms 
                                                 238.397 us   202.462 us   293.618 us 
                                                                                      
stb backend                                             100            1    2.29832 s 
                                                 22.9663 ms    22.944 ms   22.9895 ms 
                                                 116.013 us    97.589 us   143.816 us 
  • PNG loading:
-------------------------------------------------------------------------------
Benchmark PNG image loading
  Klimt (558x560)
...............................................................................

benchmark name                                  samples       iterations    estimated
                                                mean          low mean      high mean
                                                std dev       low std dev   high std dev
-------------------------------------------------------------------------------
libpng backend                                          100            1    818.32 ms 
                                                 8.18628 ms   8.16922 ms   8.25965 ms 
                                                 156.171 us    23.243 us   368.585 us 
                                                                                      
OpenCV backend                                          100            1   744.044 ms 
                                                 7.45989 ms   7.43921 ms   7.48704 ms 
                                                 120.207 us    92.235 us   162.667 us 
                                                                                      
simd backend                                            100            1   751.884 ms 
                                                 7.61521 ms   7.59533 ms   7.64222 ms 
                                                 117.722 us    88.184 us   156.898 us 
                                                                                      
stb backend                                             100            1   652.517 ms 
                                                 6.56927 ms   6.55765 ms   6.58229 ms 
                                                    62.5 us    47.774 us    85.482 us 
                                                                                      

-------------------------------------------------------------------------------
Benchmark PNG image loading
  VGA (640x480)
...............................................................................

benchmark name                                  samples       iterations    estimated
                                                mean          low mean      high mean
                                                std dev       low std dev   high std dev
-------------------------------------------------------------------------------
libpng backend                                          100            1   450.408 ms 
                                                  4.4728 ms   4.44077 ms    4.6025 ms 
                                                 288.888 us    48.553 us   678.342 us 
                                                                                      
OpenCV backend                                          100            1   372.091 ms 
                                                 3.72073 ms   3.70799 ms   3.74207 ms 
                                                  82.622 us    55.228 us   132.688 us 
                                                                                      
simd backend                                            100            1   319.085 ms 
                                                 3.20107 ms   3.19875 ms   3.20425 ms 
                                                  13.778 us    10.787 us    18.675 us 
                                                                                      
stb backend                                             100            1     275.4 ms 
                                                 2.74059 ms   2.72694 ms   2.76094 ms 
                                                  83.684 us    61.616 us   114.671 us 
                                                                                      

-------------------------------------------------------------------------------
Benchmark PNG image loading
  HD (1920x1080)
...............................................................................

benchmark name                                  samples       iterations    estimated
                                                mean          low mean      high mean
                                                std dev       low std dev   high std dev
-------------------------------------------------------------------------------
libpng backend                                          100            1    2.78479 s 
                                                 27.9608 ms   27.8779 ms   28.1109 ms 
                                                 552.809 us   340.402 us   839.504 us 
                                                                                      
OpenCV backend                                          100            1    2.25006 s 
                                                 22.4989 ms   22.4838 ms    22.513 ms 
                                                  73.942 us    62.361 us    90.517 us 
                                                                                      
simd backend                                            100            1     1.9471 s 
                                                 19.4564 ms   19.4309 ms    19.484 ms 
                                                  135.33 us   105.128 us   197.713 us 
                                                                                      
stb backend                                             100            1    1.68147 s 
                                                 16.7953 ms   16.7654 ms   16.8841 ms 
                                                 241.139 us    96.657 us   528.603 us 
  • JPEG writing:
-------------------------------------------------------------------------------
Benchmark JPEG image saving
  Klimt (558x560)
...............................................................................

benchmark name                                  samples       iterations    estimated
                                                mean          low mean      high mean
                                                std dev       low std dev   high std dev
-------------------------------------------------------------------------------
libjpeg backend                                         100            1     1.0643 s 
                                                 10.8578 ms    10.406 ms   11.3788 ms 
                                                 2.45937 ms   2.04567 ms   2.95165 ms 
                                                                                      
OpenCV backend                                          100            1    1.40481 s 
                                                 14.5863 ms   14.0433 ms   15.1899 ms 
                                                 2.90972 ms   2.41847 ms   3.64209 ms 
                                                                                      
simd backend                                            100            1   670.247 ms 
                                                 6.51971 ms   6.33599 ms   6.74576 ms 
                                                  1.0365 ms   777.071 us   1.38062 ms 
                                                                                      
stb backend                                             100            1    2.97442 s 
                                                 27.2006 ms   26.3427 ms    28.448 ms 
                                                 5.23534 ms   3.95374 ms    7.0996 ms 
                                                                                      

-------------------------------------------------------------------------------
Benchmark JPEG image saving
  VGA (640x480)
...............................................................................

benchmark name                                  samples       iterations    estimated
                                                mean          low mean      high mean
                                                std dev       low std dev   high std dev
-------------------------------------------------------------------------------
libjpeg backend                                         100            1   496.545 ms 
                                                 4.36328 ms   4.13188 ms   4.69754 ms 
                                                 1.40102 ms   1.06328 ms   1.87689 ms 
                                                                                      
OpenCV backend                                          100            1   474.411 ms 
                                                 4.16859 ms   4.04709 ms   4.42751 ms 
                                                 859.289 us   482.529 us   1.52664 ms 
                                                                                      
simd backend                                            100            1   208.956 ms 
                                                 2.12173 ms   2.04419 ms   2.23203 ms 
                                                 462.412 us   353.693 us   601.051 us 
                                                                                      
stb backend                                             100            1   801.801 ms 
                                                 8.61595 ms   8.30695 ms   9.26701 ms 
                                                 2.20405 ms   1.27782 ms   3.86606 ms 
                                                                                      

-------------------------------------------------------------------------------
Benchmark JPEG image saving
  HD (1920x1080)
...............................................................................

benchmark name                                  samples       iterations    estimated
                                                mean          low mean      high mean
                                                std dev       low std dev   high std dev
-------------------------------------------------------------------------------
libjpeg backend                                         100            1    2.18568 s 
                                                 20.3908 ms   19.7339 ms   21.3151 ms 
                                                 3.94264 ms   3.01513 ms   4.94135 ms 
                                                                                      
OpenCV backend                                          100            1    2.46353 s 
                                                 23.4013 ms   22.5072 ms   24.7013 ms 
                                                 5.42507 ms   4.11182 ms   7.04622 ms 
                                                                                      
simd backend                                            100            1    1.09612 s 
                                                  10.172 ms    10.038 ms   10.4197 ms 
                                                 905.648 us   536.039 us    1.4286 ms 
                                                                                      
stb backend                                             100            1    4.66624 s 
                                                 48.3019 ms   47.5561 ms   49.2094 ms 
                                                  4.1833 ms     3.496 ms   4.91953 ms 
  • PNG writing:
Benchmark PNG image saving
  Klimt (558x560)
...............................................................................

benchmark name                                  samples       iterations    estimated
                                                mean          low mean      high mean
                                                std dev       low std dev   high std dev
-------------------------------------------------------------------------------
libpng backend                                          100            1    11.3003 s 
                                                 109.273 ms    106.21 ms   112.149 ms 
                                                 15.1572 ms    13.871 ms   19.1454 ms 
                                                                                      
OpenCV backend                                          100            1    8.96937 s 
                                                 89.7351 ms   85.9661 ms   100.641 ms 
                                                 30.1755 ms   12.0633 ms   66.1757 ms 
                                                                                      
simd backend                                            100            1    8.16686 s 
                                                 103.356 ms   100.364 ms   107.075 ms 
                                                 16.8816 ms   13.8208 ms   25.2327 ms 
                                                                                      
stb backend                                             100            1    10.9629 s 
                                                 108.218 ms   103.496 ms   113.564 ms 
                                                 25.7068 ms   23.2856 ms   27.8249 ms 
                                                                                      

-------------------------------------------------------------------------------
Benchmark PNG image saving
  VGA (640x480)
...............................................................................

benchmark name                                  samples       iterations    estimated
                                                mean          low mean      high mean
                                                std dev       low std dev   high std dev
-------------------------------------------------------------------------------
libpng backend                                          100            1    2.06832 s 
                                                 18.5232 ms   18.0207 ms   19.3121 ms 
                                                 3.19257 ms   2.13932 ms   4.27648 ms 
                                                                                      
OpenCV backend                                          100            1   655.802 ms 
                                                 6.83681 ms   6.65356 ms   7.17696 ms 
                                                 1.23853 ms   765.282 us   1.89374 ms 
                                                                                      
simd backend                                            100            1    559.29 ms 
                                                 5.59802 ms   5.58907 ms   5.61203 ms 
                                                  56.281 us     40.82 us    79.897 us 
                                                                                      
stb backend                                             100            1    2.54966 s 
                                                 25.4369 ms   25.4028 ms   25.4758 ms 
                                                 184.899 us   147.529 us   254.654 us 
                                                                                      

-------------------------------------------------------------------------------
Benchmark PNG image saving
  HD (1920x1080)
...............................................................................

benchmark name                                  samples       iterations    estimated
                                                mean          low mean      high mean
                                                std dev       low std dev   high std dev
-------------------------------------------------------------------------------
libpng backend                                          100            1    8.41413 s 
                                                 83.9814 ms   83.6641 ms   84.5997 ms 
                                                 2.18817 ms   1.30086 ms   3.44209 ms 
                                                                                      
OpenCV backend                                          100            1    2.98178 s 
                                                 31.9812 ms   30.1187 ms   39.8633 ms 
                                                  16.916 ms   2.57513 ms   39.8225 ms 
                                                                                      
simd backend                                            100            1    2.70751 s 
                                                 27.1459 ms   27.0605 ms   27.4233 ms 
                                                 716.052 us   246.052 us   1.61046 ms 
                                                                                      
stb backend                                             100            1    17.4851 s 
                                                 173.371 ms   173.097 ms    173.72 ms 
                                                 1.57211 ms   1.26491 ms   2.07192 ms 

On my computer (Ubuntu 18.04, AVX2) and for RGBA type:

  • JPEG and PNG loading using stb_image seems to be faster than Simd (ignoring system libs like libjeg, libjpeg-turbo, OpenCV, ...)

Anything suspicious with these numbers?

@ermig1979
Copy link
Owner

Hi! Thank you for perfomance testing. These numbers are not surprised for me bacause I made optimizations only for image saving (PNG and JPEG), loading is still a reference code on the base of stb_image (with switch off SIMD). I have plans to perform optimizqations of image loading too but this task is not prioritized.

@s-trinh
Copy link
Contributor Author

s-trinh commented Nov 18, 2021

Ok, this explains my numbers.

I am interested into the in-memory image compression using JPEG to be able to use a separate thread to save images, but without saturating the RAM. So your code is useful.


In general, any optimizations for x86 and ARM and compatible for Unix/Windows platforms are useful for me. With appropriate fallbacks to regular code to be able to run the code on most of the hardware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants