Created
February 5, 2021 04:02
-
-
Save dasl-/30d5d4e4c95877b704729680ee1d7c9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/env python3 | |
import subprocess | |
import argparse | |
import time | |
import statistics | |
def parseArgs(): | |
parser = argparse.ArgumentParser(description="test ssh speed to given hostname") | |
parser.add_argument('--hostname', dest='hostname', action='store', required = True, | |
help='host to ssh onto') | |
parser.add_argument('--num-trials', dest='num_trials', action='store', default=10, type=int, | |
help='how many times to test sshing') | |
args = parser.parse_args() | |
return args | |
def command(command): | |
return (subprocess | |
.check_output(command, shell = True, ) | |
.decode("utf-8")) | |
args = parseArgs() | |
print(f'sshing onto {args.hostname} {args.num_trials} times...') | |
ssh_cmd = f'ssh pi@{args.hostname} -- hostname' | |
timings = [] | |
for i in range(0, args.num_trials): | |
start = time.time() | |
command(ssh_cmd) | |
elapsed_ms = (time.time() - start) * 1000 | |
timings.append(elapsed_ms) | |
median = round(statistics.median(timings), 2) | |
mean = round(statistics.mean(timings), 2) | |
my_min = round(min(timings), 2) | |
my_max = round(max(timings), 2) | |
print(f'{args.hostname} min: {my_min} ms') | |
print(f'{args.hostname} median: {median} ms') | |
print(f'{args.hostname} mean: {mean} ms') | |
print(f'{args.hostname} max: {my_max} ms') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment