do_latency.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:do-latency 作者: dizballanze 项目源码 文件源码
def start_test(ping_count=10, file_size="10mb", udp=False):
    results = {key: [] for key in REGIONS}
    # Latency testing
    pbar = tqdm(total=(len(REGIONS) * ping_count), desc=PADDING_FORMAT.format("Latency testing"), bar_format=BAR_FORMAT, leave=True)
    for region, host in six.iteritems(REGIONS):
        pbar.set_description(PADDING_FORMAT.format("Latency testing ({})".format(region)))
        results[region].append(do_ping(host, count=ping_count, udp=udp, hook=lambda: pbar.update(1)))
    pbar.close()
    # Download speed testing
    pbar = tqdm(total=(len(REGIONS) * 100), desc=PADDING_FORMAT.format("Download speed testing"), bar_format=BAR_FORMAT, leave=True, disable=False)
    for region, host in six.iteritems(REGIONS):
        pbar.set_description(PADDING_FORMAT.format("Download speed testing ({})".format(region)))
        url = "http://{}/{}.test".format(host, file_size)
        results[region].append(do_download(url, lambda progress: pbar.update(progress)))
    # Output sorted by latency results as table
    table_data = [[key] + value for key, value in six.iteritems(results)]
    table_data.sort(key=lambda row: float(row[1]))
    table_data.insert(0, ["Region", "Latency (ms)", "Download speed (mbps)"])
    table = AsciiTable(table_data)
    print("\n\n{}\n".format( table.table))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号