效果(纵轴为 ELPA。横轴为用时,单位毫秒。Echo Area 显示具体秒数):
可见我这边 Melpa、Melpa 官方镜像、TUNA 都超时(10 秒为 timeout),前两个不意外,TUNA 不知为何,我手动简单试了几次,有时候会卡死,有时又不会(此时也非常快),其它的三个都非常非常快。
代码如下:
- 用了 Melpa 来测试,大部分 Elpa 包都在这
- 用了 HTTP,但 HTTPS 应该也都支持
- 用了 Melpa 的 archive-contents 来测试,大小 1438834 bytes,也就是大概 1.4 M
- Timeout 为 10 秒
(defun the-fastest-elpa-mirror ()
(interactive)
(let* ((urls
(mapcar
(lambda (part)
(concat "http://" part "archive-contents"))
'("melpa.org/packages/"
"www.mirrorservice.org/sites/melpa.org/packages/"
"emacs-china.org/melpa/"
"mirrors.tuna.tsinghua.edu.cn/elpa/melpa/"
"mirrors.163.com/elpa/melpa/"
"mirrors.cloud.tencent.com/elpa/melpa/")))
(durations
(mapcar
(lambda (url)
(let ((start (current-time)))
(message "Fetching %s" url)
(call-process "curl" nil nil nil "--max-time" "10" url)
(float-time (time-subtract (current-time) start))))
urls)))
(chart-bar-quickie
'horizontal
"The fastest elpa mirror"
(mapcar (lambda (url) (url-host (url-generic-parse-url url))) urls) "Elpa"
(mapcar (lambda (d) (* 1e3 d)) durations) "ms")
(message "%s" durations)))