性能
对该模块相对于替代方案的性能进行基准测试。
¥A test to benchmark the performance of this module relative to alternatives.
启用缓存(默认)并使用 8 个以上核心的计算机(尤其是具有较大 L1/L2 CPU 缓存的计算机)可以期待更高的 libvips 性能。
¥Greater libvips performance can be expected with caching enabled (default) and using 8+ core machines, especially those with larger L1/L2 CPU caches.
相关(解)压缩库的 I/O 限制通常将决定最大吞吐量。
¥The I/O limits of the relevant (de)compression library will generally determine maximum throughput.
竞争者
¥Contenders
-
jimp v1.6.0 - 纯 JavaScript 中的图片处理。
¥jimp v1.6.0 - Image processing in pure JavaScript.
-
imagemagick v0.1.3 - 仅支持文件系统和 “has been unmaintained for a long time”。
¥imagemagick v0.1.3 - Supports filesystem only and “has been unmaintained for a long time”.
-
gm v1.25.1 - GraphicsMagick 的
gm
命令行实用程序的全功能封装器,但 “已停用”。¥gm v1.25.1 - Fully featured wrapper around GraphicsMagick’s
gm
command line utility, but “has been sunset”. -
sharp v0.34.0 / libvips v8.16.1 - 禁用 libvips 内的缓存以确保公平比较。
¥sharp v0.34.0 / libvips v8.16.1 - Caching within libvips disabled to ensure a fair comparison.
环境
¥Environment
AMD64
-
AWS EC2 us-west-2 c7a.xlarge (4x AMD EPYC 9R14)
-
Ubuntu 24.10 fad5ba7223f8
-
Node.js 22.14.0
ARM64
-
AWS EC2 us-west-2 c8g.xlarge (4x ARM Graviton4)
-
Ubuntu 24.10 133f2e05cb69
-
Node.js 22.14.0
任务:JPEG
¥Task: JPEG
解压缩 2725x2225 JPEG 图片,使用 Lanczos 3 重采样(如果可用)将大小调整为 720x588,然后以 “quality” 设置 80 压缩为 JPEG。
¥Decompress a 2725x2225 JPEG image, resize to 720x588 using Lanczos 3 resampling (where available), then compress to JPEG at a “quality” setting of 80.
注意:jimp 不支持 Lanczos 3,而是使用双三次重采样。
¥Note: jimp does not support Lanczos 3, bicubic resampling used instead.
结果:JPEG (AMD64)
¥Results: JPEG (AMD64)
模块 | 输入 | 输出 | 操作数/秒 | 加速 |
---|---|---|---|---|
jimp | buffer | buffer | 2.35 | 1.0 |
imagemagick | file | file | 10.51 | 4.5 |
gm | buffer | buffer | 11.67 | 5.0 |
gm | file | file | 11.75 | 5.1 |
sharp | stream | stream | 60.72 | 25.8 |
sharp | file | file | 62.37 | 26.5 |
sharp | buffer | buffer | 65.15 | 27.7 |
结果:JPEG (ARM64)
¥Results: JPEG (ARM64)
模块 | 输入 | 输出 | 操作数/秒 | 加速 |
---|---|---|---|---|
jimp | buffer | buffer | 2.13 | 1.0 |
imagemagick | file | file | 12.95 | 6.1 |
gm | buffer | buffer | 13.53 | 6.4 |
gm | file | file | 13.52 | 6.4 |
sharp | stream | stream | 46.58 | 21.9 |
sharp | file | file | 48.42 | 22.7 |
sharp | buffer | buffer | 50.16 | 23.6 |
任务:PNG
¥Task: PNG
解压缩 2048x1536 RGBA PNG 图片,预乘 Alpha 通道,使用 Lanczos 3 重采样(如果可用)将大小调整为 720x540,取消预乘,然后使用 “default” zlib 压缩级别 6 压缩为 PNG,并且不使用自适应滤波。
¥Decompress a 2048x1536 RGBA PNG image, premultiply the alpha channel, resize to 720x540 using Lanczos 3 resampling (where available), unpremultiply then compress as PNG with a “default” zlib compression level of 6 and without adaptive filtering.
注意:jimp 不支持预乘/取消预乘。
¥Note: jimp does not support premultiply/unpremultiply.
结果:PNG (AMD64)
¥Results: PNG (AMD64)
模块 | 输入 | 输出 | 操作数/秒 | 加速 |
---|---|---|---|---|
gm | file | file | 8.66 | 1.0 |
imagemagick | file | file | 8.79 | 1.0 |
jimp | buffer | buffer | 11.26 | 1.3 |
sharp | file | file | 27.93 | 3.2 |
sharp | buffer | buffer | 28.69 | 3.3 |
结果:PNG (ARM64)
¥Results: PNG (ARM64)
模块 | 输入 | 输出 | 操作数/秒 | 加速 |
---|---|---|---|---|
gm | file | file | 9.65 | 1.0 |
imagemagick | file | file | 9.72 | 1.0 |
jimp | buffer | buffer | 10.68 | 1.1 |
sharp | file | file | 23.90 | 2.5 |
sharp | buffer | buffer | 24.48 | 2.5 |
运行基准测试
¥Running the benchmark test
需要 Docker。
¥Requires Docker.
git clone https://github.com/lovell/sharp.gitcd sharp/test/bench./run-with-docker.sh