Skip to content

Instantly share code, notes, and snippets.

@homm

homm/ImageMagickTest.sh

Last active Jul 5, 2016
Embed
What would you like to do?
Graphic Benchmarks
#!/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"
#!/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
)
@gi11es

This comment has been minimized.

Copy link

@gi11es gi11es commented Jul 5, 2016

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?

@gi11es

This comment has been minimized.

Copy link

@gi11es gi11es commented Jul 5, 2016

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