Homebrew镜像源测速需分三类:1. Git同步速度(测info/refs文件下载速率,≥0.5MB/s为良);2. API响应速度(测formulae/json请求总耗时,<0.3s为优);3. Bottle下载速度(测真实bottle包速率,≥5MB/s为高速)。
直接测 homebrew 镜像源的速度,不能只看 ping 或单纯 curl 一个页面——因为 homebrew 的下载涉及 git 仓库拉取、api 查询、bottle 二进制包下载三个不同环节,每个环节走的地址和协议都不一样。所以真正有效的测速,得分别对这三类地址做实测下载速度。
测 Git 仓库同步速度(影响 brew update)
Homebrew 更新时,本质是执行 git pull,所以要测的是镜像源上 brew.git 和 homebrew-core.git 的克隆/拉取效率。最简单的方法是用 curl 模拟小文件下载(Git 的 info/refs 文件很小,响应快,能反映首字节延迟和基础连接质量):
- 清华源:
curl -o /dev/null -s -w '%{speed_download}\n' https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git/info/refs?service=git-upload-pack - 中科大源:
curl -o /dev/null -s -w '%{speed_download}\n' https://mirrors.ustc.edu.cn/brew.git/info/refs?service=git-upload-pack - 阿里云源:
curl -o /dev/null -s -w '%{speed_download}\n' https://mirrors.aliyun.com/homebrew/brew.git/info/refs?service=git-upload-pack
输出值单位是 MB/s;0.5 以上算良好,低于 0.1 基本说明该源当前 Git 同步链路有问题。
测 API 响应速度(影响 brew search / brew info)
Homebrew 查询软件信息时会访问 /api/ 端点(如 https://ghcr.io/v2/ 或镜像提供的替代 API)。清华、中科大、阿里云都提供了独立的 API 镜像地址:
- 清华 API:
curl -o /dev/null -s -w 'time:%{time_total}s, code:%{http_code}\n' https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api/formulae/mysql.json - 中科大 API:
curl -o /dev/null -s -w 'time:%{time_total}s, code:%{http_code}\n' https://mirrors.ustc.edu.cn/homebrew-bottles/api/formulae/python.json
关注 time_total,低于 0.3 秒为优,超过 1 秒说明 API 延迟高,搜索和依赖解析会卡顿。
测 Bottle 下载速度(影响 brew install 实际耗时)
Bottle 是安装时最大的数据块,比如 node、ffmpeg 的预编译包动辄百 MB。测速要选一个真实存在的 Bottle 地址(可用 brew fetch --bottle-tag=arm64_monterey node 先生成 URL,或直接测通用路径):
- 清华 Bottle:
curl -o /dev/null -s -w '%{speed_download}\n' https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/node-20.15.0.arm64_monterey.bottle.tar.gz - 阿里云 Bottle:
curl -o /dev/null -s -w '%{speed_download}\n' https://mirrors.aliyun.com/homebrew-bottles/python-3.12.5.arm64_monterey.bottle.tar.gz
注意:如果返回 404,说明该版本未同步,换一个常见包(如 wget、git)再试;稳定在 5 MB/s 以上才算高速,低于 1 MB/s 安装大包会明显拖慢。
一键脚本自动比对(推荐日常使用)
把上面三类测试封装成脚本,能省去手动复制粘贴。以下命令可直接运行(支持 Apple Silicon 和 Intel):
(保存为brew-speed-test.sh,然后 chmod +x brew-speed-test.sh && ./brew-speed-test.sh)
脚本会并行测试清华、中科大、阿里云三源的 Git / API / Bottle 三项指标,并按综合得分排序,标出当前最优组合。它不修改任何配置,纯读取型诊断,安全可靠。

















