start testing for bandwidth parser
authorAndrew Lorimer <andrew@lorimer.id.au>
Sun, 5 May 2019 12:05:48 +0000 (22:05 +1000)
committerAndrew Lorimer <andrew@lorimer.id.au>
Sun, 5 May 2019 12:05:48 +0000 (22:05 +1000)
bandwidth-test.sh [new file with mode: 0755]
diff --git a/bandwidth-test.sh b/bandwidth-test.sh
new file mode 100755 (executable)
index 0000000..67953ef
--- /dev/null
@@ -0,0 +1,36 @@
+format() {
+  if [ $1 -lt 100 ]; then # round down <.1 kb
+    printf '000K'
+  elif [ $1 -lt $((10**3)) ]; then
+    printf '0%sk' $(echo "scale=1;$1 / 10^3" | bc -l)
+  elif [ $1 -lt 9950 ]; then
+    printf '%sk' $(round `echo "$1 / 10^3" | bc -l` 1)
+  elif [ $1 -lt 99500 ]; then
+    printf '0%sk' $(round `echo $1 / 10^3 | bc -l` 0)
+  elif [ $1 -lt 999500 ]; then
+    printf '%sk' $(round `echo $1 / 10^3 | bc -l` 0)
+  elif [ $1 -lt 1050000 ]; then
+    printf '%sm' $(echo `round $(echo "$1 / 10^7" | bc -l) 1`*10 | bc -l)
+  elif [ $1 -lt 9950000 ]; then
+    printf '%sm' $(round `echo "$1 / 10^6" | bc -l` 1)
+  elif [ $1 -lt 99500000 ]; then
+    printf '0%sm' $(round `echo "$1 / 10^6" | bc -l` 0)
+  elif [ $1 -lt 999500000 ]; then
+    printf '%sm' $(round `echo $1 / 10^6 | bc -l` 0)
+  elif [ $1 -lt 9950000000 ]; then
+    printf '%sg' $(round `echo $1 / 10^9 | bc -l` 1)
+  elif [ $1 -lt 99500000000 ]; then
+    printf '0%sg' $(round `echo $1 / 10^9 | bc -l` 0)
+  elif [ $1 -lt 999500000000 ]; then
+    printf '%sg' $(round `echo $1 / 10^9 | bc -l` 0)
+  else
+    printf 'fast'
+  fi
+}
+
+round() {
+  echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc))
+}
+
+for x in {1000..10000}; do format $(( $x * 10 )); done
+