Skip to content

Commit

Permalink
methodology, why not contributed
Browse files Browse the repository at this point in the history
  • Loading branch information
homm committed Jul 2, 2016
1 parent 2e55786 commit d2eefef
Showing 1 changed file with 52 additions and 27 deletions.
79 changes: 52 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,32 @@ the result will be 61.7 Mpx/s.
- Pillow 3.2.0
- Pillow-SIMD 3.2.0.post1

Source | Operation | Filter | IM | Pillow | SIMD SSE4 | SIMD AVX2
----------|---------------------|---------|------|--------|-----------|-----------
7712x4352 | Resize to 16x16 | Bilinear| 27.0 | 217 | 456 | 545
| | Bicubic | 10.9 | 115 | 240 | 278
| | Lanczos | 6.6 | 76.1 | 162 | 194
| Resize to 320x180 | Bilinear| 32.0 | 166 | 354 | 410
| | Bicubic | 16.5 | 92.3 | 198 | 204
| | Lanczos | 11.0 | 63.2 | 133 | 147
| Resize to 2048x1155 | Bilinear| 20.7 | 87.6 | 202 | 217
| | Bicubic | 12.2 | 65.7 | 126 | 130
| | Lanczos | 8.7 | 41.3 | 88.2 | 95.6
| Blur | 1px | 8.1 | 17.1 | 37.8
| | 10px | 2.6 | 17.4 | 39.0
| | 100px | 0.3 | 17.2 | 39.0
1920x1280 | Resize to 16x16 | Bilinear| 41.6 | 196 | 422 | 489
| | Bicubic | 18.9 | 102 | 225 | 263
| | Lanczos | 13.7 | 68.6 | 118 | 167
| Resize to 320x180 | Bilinear| 27.6 | 111 | 196 | 197
| | Bicubic | 14.5 | 66.3 | 154 | 162
| | Lanczos | 9.8 | 44.3 | 102 | 107
| Resize to 2048x1155 | Bilinear| 9.1 | 20.7 | 71.3 | 72.6
| | Bicubic | 6.3 | 16.9 | 49.3 | 54.3
| | Lanczos | 4.7 | 14.6 | 36.8 | 40.6
| Blur | 1px | 8.7 | 16.2 | 35.7
| | 10px | 2.8 | 16.7 | 35.4
| | 100px | 0.4 | 16.4 | 36.2
Source | Operation | Filter | IM | Pillow | SIMD SSE4 | SIMD AVX2
----------|-------------------------|---------|------|--------|-----------|-----------
7712x4352 | **Resize to 16x16** | Bilinear| 27.0 | 217 | 456 | 545
| | Bicubic | 10.9 | 115 | 240 | 278
| | Lanczos | 6.6 | 76.1 | 162 | 194
| **Resize to 320x180** | Bilinear| 32.0 | 166 | 354 | 410
| | Bicubic | 16.5 | 92.3 | 198 | 204
| | Lanczos | 11.0 | 63.2 | 133 | 147
| **Resize to 2048x1155** | Bilinear| 20.7 | 87.6 | 202 | 217
| | Bicubic | 12.2 | 65.7 | 126 | 130
| | Lanczos | 8.7 | 41.3 | 88.2 | 95.6
| **Blur** | 1px | 8.1 | 17.1 | 37.8
| | 10px | 2.6 | 17.4 | 39.0
| | 100px | 0.3 | 17.2 | 39.0
1920x1280 | **Resize to 16x16** | Bilinear| 41.6 | 196 | 422 | 489
| | Bicubic | 18.9 | 102 | 225 | 263
| | Lanczos | 13.7 | 68.6 | 118 | 167
| **Resize to 320x180** | Bilinear| 27.6 | 111 | 196 | 197
| | Bicubic | 14.5 | 66.3 | 154 | 162
| | Lanczos | 9.8 | 44.3 | 102 | 107
| **Resize to 2048x1155** | Bilinear| 9.1 | 20.7 | 71.3 | 72.6
| | Bicubic | 6.3 | 16.9 | 49.3 | 54.3
| | Lanczos | 4.7 | 14.6 | 36.8 | 40.6
| **Blur** | 1px | 8.7 | 16.2 | 35.7
| | 10px | 2.8 | 16.7 | 35.4
| | 100px | 0.4 | 16.4 | 36.2


### Some conclusion
Expand All @@ -92,7 +92,20 @@ All tests done on Ubuntu 14.04 64-bit runing on
Intel Core i5 4258U with AVX2 CPU on single thread.

ImageMagick performance measured with command-line tool `convert` with
`-verbose` and `-bench` arguments
`-verbose` and `-bench` arguments. I'm using command line because
I needed to test latest version and this is to easist way to do that.
All operations are producing exactly the same result.
Resizing filters compliance:

- PIL.Image.BILINEAR == Triangle
- PIL.Image.BICUBIC == Catrom
- PIL.Image.LANCZOS == Lanczos

In ImageMagick the radius of gaussian blur called sigma and second parameter
is called radius. In fact there should not be additional parameters for
*gaussian blur*, because if the radius is too small, this is *not*
gaussian blur anymore. And if the radius is big, this does not give any
advantages, but makes operation slower. For test I set radius to sigma × 2.5.

Following script were used for testing:
https://gist.github.com/homm/f9b8d8a84a57a7e51f9c2a5828e40e63
Expand All @@ -109,6 +122,18 @@ benchmakrs. And result is

## Why not to contribute SIMD to the original Pillow

Well, this is not so simple. First of all, Pillow support large number
of architectures, not only x86. But even for x86 platforms Pillow orfen
distributed via precompiled binaries. To integrate SIMD in precompiled binaries
we need to do runtime checks of CPU capabilites.
To compile code with runtime checks we need to pass `-mavx2` option
to compiller. But this automaticaly activates all `if (__AVX2__)` and below
conditions. And SIMD instructions under such conditions are exist
even in standard C library and they do not have any runtime checks.
Currently I don't know a way how to tell to compiller to allow SIMD
instrustions in the code but *do not allow* using such instructions without
runtime checks.


## Installation

Expand Down

0 comments on commit d2eefef

Please sign in to comment.