Skip to content

Performance ​

Results ​

Laravel Go Image runs 25 of the 27 benchmarked operations faster than Intervention Image 4.4.2 with the GD driver. It encodes GIFs 19 times faster, blurs 8 times faster, and reduces colors 15 times faster. Only JPEG and PNG decoding are slower.

How many times faster Go is than PHP

Median time per operation

These results come from a Linux machine with 2 CPUs, Go 1.27.4, PHP 8.4.28, and GD 2.3.3. Go spreads most operations over every CPU, while GD uses one, so results depend on the number of CPUs.

OperationGo (ms)PHP (ms)Go is
decode JPEG37172.2× slower
decode PNG56481.2× slower
encode JPEG22341.5× faster
encode PNG2708303.1× faster
encode WebP542624.9× faster
encode GIF3361218.6× faster
thumbnail30371.2× faster
scale29712.4× faster
cover15473.1× faster
contain36772.2× faster
crop7.2669.1× faster
rotate 90°23994.2× faster
rotate 45°1093112.9× faster
flip20261.3× faster
grayscale13443.4× faster
brightness5.8518.7× faster
contrast5.96410.9× faster
gamma5.816127.9× faster
colorize18512.8× faster
invert6.5487.4× faster
blur947868.4× faster
sharpen571833.2× faster
pixelate40441.1× faster
reduce colors2941514.5× faster
insert3.2268.2× faster
draw shapes14282.0× faster
text2.62810.9× faster

What the benchmark measures ​

Both sides read the same inputs: a generated 1920x1080 test image with smooth gradients and noise, saved as JPEG and PNG, a 200x100 translucent logo, and the Go Regular font. Each operation runs once to warm up, then repeats for at least 5 runs and up to 50 runs or one second, and the run reports its median. The benchmark runs each side three times, and the table and charts show the median of the three runs, so one noisy run doesn't skew them.

Every operation except the decode and thumbnail ones starts from a copy of an already decoded photo, so it doesn't measure decoding. The PHP side copies the decoded image with clone, and the Go side with Clone.

WebP encoding on both sides is lossy at quality 75. The Go numbers use the system libwebp. Without it, the package falls back to libwebp in WebAssembly, which took 241 ms, a little faster than GD's 262 ms. See WebP encoding.

Where PHP is faster ​

GD decodes JPEG with libjpeg-turbo, which uses SIMD instructions. The package's JPEG decoder reads baseline scans with a fast bit reader and lookup tables, and renders the pixels on every CPU, but the entropy decoding of a scan can't be split across CPUs, and without SIMD it takes about half of the decode time. JPEG decoding still takes about twice as long as GD's.

PNG decoding spends most of its time inflating zlib data. The package inflates with github.com/klauspost/compress on one goroutine while it filters rows on another, but a single zlib stream can't be split, and C's zlib inflates faster than Go, so PNG decoding takes about 1.2 times as long.

Operations that decode a JPEG to make it smaller, such as the thumbnail, avoid most of that cost. The package decodes JPEGs lazily and renders them at 1/2, 1/4, or 1/8 scale when an operation such as Cover or Scale shrinks them enough, rendering only the area it keeps, so the thumbnail is faster than GD's.

Running the benchmarks ​

The benchmarks live in the repository's benchmarks directory. run.sh prepares the inputs, runs both sides, and redraws the charts in art/. It needs Go, PHP with GD, and Composer:

shell
./benchmarks/run.sh

Released under the MIT License.