Skip to content

Instantly share code, notes, and snippets.

@kou1okada
Last active November 2, 2021 23:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kou1okada/9581971e32cadc6306fc to your computer and use it in GitHub Desktop.
Save kou1okada/9581971e32cadc6306fc to your computer and use it in GitHub Desktop.
Benchmark cygwin mirrors.

Benchmark cygwin mirrors

This script can determine the best mirror of cygwin before installing cygwin.

Below oneliner downloads and executes benchmark_cygwin_mirrors.bat.

powershell -Command "Import-Module BitsTransfer; Start-BitsTransfer https://gist.githubusercontent.com/kou1okada/9581971e32cadc6306fc/raw/benchmark_cygwin_mirrors.bat" && benchmark_cygwin_mirrors.bat

Below is an example of the result.

>powershell -Command "Import-Module BitsTransfer; Start-BitsTransfer https://gist.githubusercontent.com/kou1okada/9581971e32cadc6306fc/raw/benchmark_cygwin_mirrors.bat" && benchmark_cygwin_mirrors.bat
Benchmark cygwin mirrors.
0.3449061 http://mirrors.neusoft.edu.cn/cygwin/
Update the best: 0.3449061 http://mirrors.neusoft.edu.cn/cygwin/
0.2414021 http://mirrors.ustc.edu.cn/cygwin/
Update the best: 0.2414021 http://mirrors.ustc.edu.cn/cygwin/
0.1870961 ftp://ftp.iij.ad.jp/pub/cygwin/
Update the best: 0.1870961 ftp://ftp.iij.ad.jp/pub/cygwin/
0.0369863 http://ftp.iij.ad.jp/pub/cygwin/
Update the best: 0.0369863 http://ftp.iij.ad.jp/pub/cygwin/
0.6265428 http://ftp-stud.hs-esslingen.de/pub/Mirrors/sources.redhat.com/cygwin/

0.5858283 http://sourceware.mirrors.tds.net/pub/sourceware.org/cygwin/

The best mirror is 0.0369863 http://ftp.iij.ad.jp/pub/cygwin/
@ECHO OFF
ECHO Benchmark cygwin mirrors.
powershell -Command ^
"^
$len = 0;^
$min = 1e9;^
$best = """nothing""";^
Import-Module BitsTransfer;^
Start-BitsTransfer https://cygwin.com/mirrors.lst;^
foreach($mirror in Get-Content mirrors.lst) {^
$mirror = $mirror -split """;""";^
$bz2 = """$($mirror[0])x86_64/sha512.sum""";^
try {^
$dur = (Measure-Command {^
$req = [System.Net.WebRequest]::Create($bz2);^
$req.Timeout = 1000;^
$res = $req.getResponse();^
}).TotalSeconds;^
$progress = """$dur $($mirror[0])""";^
Write-Host -NoNewLine """`r$(""" """ * $len)`r$($progress)""";^
$len = $progress.Length;^
if ($dur -lt $min) {^
$min = $dur;^
$best = $mirror[0]; Write-Host """`nUpdate the best: $min $best""";^
}^
}^
catch [Exception] { }^
};^
Write-Host; Write-Host """`nThe best mirror is $min $best""";^
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment