mirror of
https://github.com/XIU2/CloudflareSpeedTest.git
synced 2026-03-16 20:15:59 +08:00
the speed progress bar shows test count
This commit is contained in:
6
main.go
6
main.go
@@ -80,6 +80,9 @@ https://github.com/XIU2/CloudflareSpeedTest
|
|||||||
flag.Usage = func() { fmt.Print(help) }
|
flag.Usage = func() { fmt.Print(help) }
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if task.MinSpeed > 0 && time.Duration(maxDelay)*time.Millisecond == utils.InputMaxDelay {
|
||||||
|
fmt.Println("[警告] '-sl' 参数建议和 '-tl' 参数一起使用")
|
||||||
|
}
|
||||||
utils.InputMaxDelay = time.Duration(maxDelay) * time.Millisecond
|
utils.InputMaxDelay = time.Duration(maxDelay) * time.Millisecond
|
||||||
utils.InputMinDelay = time.Duration(minDelay) * time.Millisecond
|
utils.InputMinDelay = time.Duration(minDelay) * time.Millisecond
|
||||||
task.Timeout = time.Duration(downloadTime) * time.Second
|
task.Timeout = time.Duration(downloadTime) * time.Second
|
||||||
@@ -112,7 +115,10 @@ func main() {
|
|||||||
if versionNew != "" {
|
if versionNew != "" {
|
||||||
fmt.Printf("\n*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***\n", versionNew)
|
fmt.Printf("\n*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***\n", versionNew)
|
||||||
}
|
}
|
||||||
|
endPrint()
|
||||||
|
}
|
||||||
|
|
||||||
|
func endPrint() {
|
||||||
if runtime.GOOS == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭)
|
if runtime.GOOS == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭)
|
||||||
fmt.Println("\n按下 回车键 或 Ctrl+C 退出。")
|
fmt.Println("\n按下 回车键 或 Ctrl+C 退出。")
|
||||||
var pause int
|
var pause int
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func checkDownloadDefault() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDownloadSpeed(ipSet utils.PingDelaySet) (sppedSet utils.DownloadSpeedSet) {
|
func TestDownloadSpeed(ipSet utils.PingDelaySet) (speedSet utils.DownloadSpeedSet) {
|
||||||
checkDownloadDefault()
|
checkDownloadDefault()
|
||||||
if Disable {
|
if Disable {
|
||||||
return utils.DownloadSpeedSet(ipSet)
|
return utils.DownloadSpeedSet(ipSet)
|
||||||
@@ -65,22 +65,25 @@ func TestDownloadSpeed(ipSet utils.PingDelaySet) (sppedSet utils.DownloadSpeedSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("开始下载测速(下载速度下限:%.2f MB/s,下载测速数量:%d,下载测速队列:%d):\n", MinSpeed, TestCount, testNum)
|
fmt.Printf("开始下载测速(下载速度下限:%.2f MB/s,下载测速数量:%d,下载测速队列:%d):\n", MinSpeed, TestCount, testNum)
|
||||||
bar := utils.NewBar(testNum)
|
bar := utils.NewBar(TestCount)
|
||||||
for i := 0; i < testNum; i++ {
|
for i := 0; i < testNum; i++ {
|
||||||
speed := downloadHandler(ipSet[i].IP)
|
speed := downloadHandler(ipSet[i].IP)
|
||||||
ipSet[i].DownloadSpeed = speed
|
ipSet[i].DownloadSpeed = speed
|
||||||
bar.Grow(1)
|
|
||||||
// 在每个 IP 下载测速后,以 [下载速度下限] 条件过滤结果
|
// 在每个 IP 下载测速后,以 [下载速度下限] 条件过滤结果
|
||||||
if speed >= MinSpeed*1024*1024 {
|
if speed >= MinSpeed*1024*1024 {
|
||||||
sppedSet = append(sppedSet, ipSet[i]) // 高于下载速度下限时,添加到新数组中
|
bar.Grow(1)
|
||||||
if len(sppedSet) == TestCount { // 凑够满足条件的 IP 时(下载测速数量 -dn),就跳出循环
|
speedSet = append(speedSet, ipSet[i]) // 高于下载速度下限时,添加到新数组中
|
||||||
|
if len(speedSet) == TestCount { // 凑够满足条件的 IP 时(下载测速数量 -dn),就跳出循环
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bar.Done()
|
bar.Done()
|
||||||
|
if len(speedSet) == 0 { // 没有符合速度限制的数据,返回所有测试数据
|
||||||
|
speedSet = utils.DownloadSpeedSet(ipSet)
|
||||||
|
}
|
||||||
// 按速度排序
|
// 按速度排序
|
||||||
sort.Sort(sppedSet)
|
sort.Sort(speedSet)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user