Skip to content

Instantly share code, notes, and snippets.

@eschen42
Last active August 21, 2022 20:37
Show Gist options
  • Save eschen42/8330d990da56be172a8b7a74620452ca to your computer and use it in GitHub Desktop.
Save eschen42/8330d990da56be172a8b7a74620452ca to your computer and use it in GitHub Desktop.
pingstat.icn - compute statistics for unix ping output
#!/bin/env icon
############################################################################
#
# File: pingstat.icn
#
# Subject: pingstat.icn - compute statistics for unix ping output
#
# Author: Arthur Eschenlauer (https://orcid.org/0000-0002-2882-0508)
#
# Date: 21 August, 2022
#
# URL: https://gist.github.com/eschen42/8330d990da56be172a8b7a74620452ca
#
############################################################################
#
# This file is in the public domain. Art Eschenlauer has waived all
# copyright and related or neighboring rights to:
# pingstat.icn - compute statistics for unix ping output
# For details, see:
# https://creativecommons.org/publicdomain/zero/1.0/
#
# If you require a specific license and public domain status is not suffi-
# cient for your needs, please substitute the MIT license (see below), bearing
# in mind that the copyright "claim" is solely to meet your requirements
# and does not imply any restriction on use or copying by the author:
#
# Copyright (c) 2022, Arthur Eschenlauer
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject
# to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
############################################################################
#
# This program parses the output of the unix ping command to compile
# statistics (mean, max, min, std dev, and std err) for ping times.
#
############################################################################
#
# Requires: none
#
############################################################################
#
# Links: none
#
############################################################################
#
$define TIME " time="
procedure main()
local line, x, x_min, x_max, s, ss, n, sd, se
#&dump := 1
s := ss := n := x_max := 0
x_min := 1000
while line := read() do line ? {
tab(find(TIME)) | next
move(*TIME)
x := tab(find(" ms")) | next
s +:= x
ss +:= x^2
n +:= 1
x_min >:= x
x_max <:= x
}
write("x_min = ", x_min, "; x_max = ", x_max, "; x_mean = ", s / n)
sd := sqrt(s*s - ss)/(n - 1)
se := sd/sqrt(n)
write("sd = ", sd, "; se = ",se)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment