This repository is a companion for vercel/next.js#20765, which aims to bring first-class support for the AVIF image format, thanks to sharp. This repo is helpful to compare the time taken to convert images to WebP & AVIF (or actually any format that sharp can support).
Every run reads the source image from disk, rotates (if there's EXIF data asking to do it), reads metadata, and converts the image to the target format (without writing to disk). I'm not including the write in the benchmark because it doesn't affect the image conversion.
./run-bench.sh <file-path> <avif/webp> <run-count>
Example
./run-bench.sh pexels-sam-kolder-2387871-S.jpg avif 100
All benchmarks were run on my mid-2014 13" MacBook Pro with a 2.6 GHz Dual-Core Intel Core i5 processor and 8 GB 1600 MHz DDR3 RAM (with Chrome, Firefox, MS Edge, Slack & VSCode running).
Test images from โ
- https://www.pexels.com/photo/person-sitting-in-front-of-the-taj-mahal-2387871/ (JPG)
- https://undraw.co/illustrations (PNG)
Converting a large JPG image (1920โรโ2504) to WebP (total runtime of 2m 15s for 1000 runs)
๎ฐ ./run-bench.sh pexels-sam-kolder-2387871-L.jpg webp 1000
Sharp pexels-sam-kolder-2387871-L.jpg -> webp Conversion (1000 runs)
Average time = .2961174730 ms
Converting a large JPG image (1920โรโ2504) to AVIF (total runtime of 2m 24s for 1000 runs)
๎ฐ ./run-bench.sh pexels-sam-kolder-2387871-L.jpg avif 1000
Sharp pexels-sam-kolder-2387871-L.jpg -> avif Conversion (1000 runs)
Average time = .2261837420 ms
Converting a medium JPG image (1280โรโ1669) to WebP (total runtime of 2m 16s for 1000 runs)
๎ฐ ./run-bench.sh pexels-sam-kolder-2387871-M.jpg webp 1000
Sharp pexels-sam-kolder-2387871-M.jpg -> webp Conversion (1000 runs)
Average time = .2761548210 ms
Converting a medium JPG image (1280โรโ1669) to AVIF (total runtime of 2m 23s for 1000 runs)
๎ฐ ./run-bench.sh pexels-sam-kolder-2387871-M.jpg avif 1000
Sharp pexels-sam-kolder-2387871-M.jpg -> avif Conversion (1000 runs)
Average time = .2373165780 ms
Converting a small JPG image (640โรโ834) to WebP (total runtime of 2m 23s)
๎ฐ ./run-bench.sh pexels-sam-kolder-2387871-S.jpg webp 1000
Sharp pexels-sam-kolder-2387871-S.jpg -> webp Conversion (1000 runs)
Average time = .2731627210 ms
Converting a small JPG image (640โรโ834) to AVIF (total runtime of 2m 25s for 1000 runs)
๎ฐ ./run-bench.sh pexels-sam-kolder-2387871-S.jpg avif 1000
Sharp pexels-sam-kolder-2387871-S.jpg -> avif Conversion (1000 runs)
Average time = .2406256660 ms
Converting a medium PNG image (1275โรโ916) to WebP (total runtime of 2m 15s for 1000 runs)
๎ฐ ./run-bench.sh undraw_new_year_2021_2neh-M.png webp 1000
Sharp undraw_new_year_2021_2neh-M.png -> webp Conversion (1000 runs)
Average time = .2583528300 ms
Converting a medium PNG image (1275โรโ916) to AVIF (total runtime of 2m 32s for 1000 runs)
๎ฐ ./run-bench.sh undraw_new_year_2021_2neh-M.png avif 1000
Sharp undraw_new_year_2021_2neh-M.png -> avif Conversion (1000 runs)
Average time = .2347853600 ms
About CPU and Memory usage
CPU and memory usage was very negligible (given how well optimized sharp is) and so aren't included in the results.