From 2c46cfcd0fc6513e1eef036eea653b2c612fb2de Mon Sep 17 00:00:00 2001 From: mz <2392368224@qq.com> Date: Sat, 13 Nov 2021 22:57:18 +0800 Subject: [PATCH] the speed progress bar shows test count --- main.go | 6 ++++++ task/download.go | 15 +++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 5bcc336..267c91d 100644 --- a/main.go +++ b/main.go @@ -80,6 +80,9 @@ https://github.com/XIU2/CloudflareSpeedTest flag.Usage = func() { fmt.Print(help) } 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.InputMinDelay = time.Duration(minDelay) * time.Millisecond task.Timeout = time.Duration(downloadTime) * time.Second @@ -112,7 +115,10 @@ func main() { if versionNew != "" { fmt.Printf("\n*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***\n", versionNew) } + endPrint() +} +func endPrint() { if runtime.GOOS == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭) fmt.Println("\n按下 回车键 或 Ctrl+C 退出。") var pause int diff --git a/task/download.go b/task/download.go index 28d9b45..a16a4bd 100644 --- a/task/download.go +++ b/task/download.go @@ -50,7 +50,7 @@ func checkDownloadDefault() { } } -func TestDownloadSpeed(ipSet utils.PingDelaySet) (sppedSet utils.DownloadSpeedSet) { +func TestDownloadSpeed(ipSet utils.PingDelaySet) (speedSet utils.DownloadSpeedSet) { checkDownloadDefault() if Disable { 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) - bar := utils.NewBar(testNum) + bar := utils.NewBar(TestCount) for i := 0; i < testNum; i++ { speed := downloadHandler(ipSet[i].IP) ipSet[i].DownloadSpeed = speed - bar.Grow(1) // 在每个 IP 下载测速后,以 [下载速度下限] 条件过滤结果 if speed >= MinSpeed*1024*1024 { - sppedSet = append(sppedSet, ipSet[i]) // 高于下载速度下限时,添加到新数组中 - if len(sppedSet) == TestCount { // 凑够满足条件的 IP 时(下载测速数量 -dn),就跳出循环 + bar.Grow(1) + speedSet = append(speedSet, ipSet[i]) // 高于下载速度下限时,添加到新数组中 + if len(speedSet) == TestCount { // 凑够满足条件的 IP 时(下载测速数量 -dn),就跳出循环 break } } } bar.Done() + if len(speedSet) == 0 { // 没有符合速度限制的数据,返回所有测试数据 + speedSet = utils.DownloadSpeedSet(ipSet) + } // 按速度排序 - sort.Sort(sppedSet) + sort.Sort(speedSet) return }