From 77ee5f86e0c36d06b5d41c8b04faba75415a3503 Mon Sep 17 00:00:00 2001 From: Andrew Lorimer Date: Sun, 5 May 2019 22:05:48 +1000 Subject: [PATCH] start testing for bandwidth parser --- bandwidth-test.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 bandwidth-test.sh diff --git a/bandwidth-test.sh b/bandwidth-test.sh new file mode 100755 index 0000000..67953ef --- /dev/null +++ b/bandwidth-test.sh @@ -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 + -- 2.47.0