Last active
July 5, 2016 11:22
-
-
Save homm/f9b8d8a84a57a7e51f9c2a5828e40e63 to your computer and use it in GitHub Desktop.
Graphic Benchmarks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SRC=$1 | |
RUNS=5 | |
IM="~/ImageMagick8/bin/convert -bench $RUNS -limit thread 1" | |
# IM="gm benchmark -iterations $RUNS convert -limit threads 1" | |
RES="2>&1 | grep '=>/dev/null' | grep -Po '\d+:\K\d+\.\d+' | sort | sed '3!d'" | |
echo -n "Triangle 16x16 " | |
eval "$IM -verbose $SRC -filter Triangle -resize 16x16! bmp:/dev/null $RES" | |
echo -n "Catrom 16x16 " | |
eval "$IM -verbose $SRC -filter Catrom -resize 16x16! bmp:/dev/null $RES" | |
echo -n "Lanczos 16x16 " | |
eval "$IM -verbose $SRC -filter Lanczos -resize 16x16! bmp:/dev/null $RES" | |
echo -n "Triangle 320x180 " | |
eval "$IM -verbose $SRC -filter Triangle -resize 320x180! bmp:/dev/null $RES" | |
echo -n "Catrom 320x180 " | |
eval "$IM -verbose $SRC -filter Catrom -resize 320x180! bmp:/dev/null $RES" | |
echo -n "Lanczos 320x180 " | |
eval "$IM -verbose $SRC -filter Lanczos -resize 320x180! bmp:/dev/null $RES" | |
echo -n "Triangle 2048x1155 " | |
eval "$IM -verbose $SRC -filter Triangle -resize 2048x1155! bmp:/dev/null $RES" | |
echo -n "Catrom 2048x1155 " | |
eval "$IM -verbose $SRC -filter Catrom -resize 2048x1155! bmp:/dev/null $RES" | |
echo -n "Lanczos 2048x1155 " | |
eval "$IM -verbose $SRC -filter Lanczos -resize 2048x1155! bmp:/dev/null $RES" | |
echo -n "Blur 1px " | |
eval "$IM -verbose $SRC -blur 2.5x1 bmp:/dev/null $RES" | |
echo -n "Blur 10px " | |
eval "$IM -verbose $SRC -blur 25x10 bmp:/dev/null $RES" | |
echo -n "Blur 100px " | |
eval "$IM -verbose $SRC -blur 250x100 bmp:/dev/null $RES" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from PIL import Image, ImageOps | |
import time | |
import sys | |
def blur(im, *args): | |
return im._new(ImageOps.gaussian_blur(im, *args)) | |
im = Image.open(sys.argv[1]) | |
im.load() | |
for method, args, desc in [ | |
(Image.Image.resize, ((16, 16), Image.BILINEAR), '16x16 bil'), | |
(Image.Image.resize, ((16, 16), Image.BICUBIC), '16x16 bic'), | |
(Image.Image.resize, ((16, 16), Image.LANCZOS), '16x16 lzs'), | |
(Image.Image.resize, ((320, 180), Image.BILINEAR), '320x180 bil'), | |
(Image.Image.resize, ((320, 180), Image.BICUBIC), '320x180 bic'), | |
(Image.Image.resize, ((320, 180), Image.LANCZOS), '320x180 lzs'), | |
(Image.Image.resize, ((2048, 1155), Image.BILINEAR), '2048x1155 bil'), | |
(Image.Image.resize, ((2048, 1155), Image.BICUBIC), '2048x1155 bic'), | |
(Image.Image.resize, ((2048, 1155), Image.LANCZOS), '2048x1155 lzs'), | |
(blur, (1,), 'blur 1px'), | |
(blur, (10,), 'blur 10px'), | |
(blur, (100,), 'blur 100px'), | |
]: | |
times = [] | |
for _ in range(11): | |
start = time.time() | |
method(im, *args) | |
times.append(time.time() - start) | |
sys.stdout.write('.') | |
sys.stdout.flush() | |
method(im, *args).save('_pil ' + desc + '.jpg', quality=100) | |
times.sort() | |
duration = times[len(times) // 2] | |
pixels = im.size[0] * im.size[1] | |
print '\r>>> {:14} {:8.5f} s {:8.2f} Mpx/s'.format( | |
desc, duration, pixels / duration / 1024 / 1024 | |
) |
Github swallowed my previous comment... I was saying that it would be interesting to also compare IM's -thumbnail + jpeg:size to Pillow's thumbnail(). Because if you're looking for performance over perfect fidelity when downscaling JPGs, sampled reading is the fastest option.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why use bmp in the IM case? jpg:/dev/null would make more sense, as well as -quality 100 probably. And in the pillow test, why not save to /dev/null as well?