| OLD | NEW |
| (Empty) |
| 1 #!/bin/bash | |
| 2 # | |
| 3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 4 # for details. All rights reserved. Use of this source code is governed by a | |
| 5 # BSD-style license that can be found in the LICENSE file. | |
| 6 | |
| 7 # This file is repsonsible for performing the averag and standard deviation | |
| 8 # for a specific metrics over a given set of metrics in a file. | |
| 9 # This should be included in other compiler scripts, or used through | |
| 10 # sample_metrics.sh | |
| 11 | |
| 12 AVERAGE=0 | |
| 13 STDEV=0 | |
| 14 COUNT=0 | |
| 15 | |
| 16 function do_math_return() { | |
| 17 local sum=0 | |
| 18 local count=0 | |
| 19 local time | |
| 20 for time in $2 | |
| 21 do | |
| 22 sum=$(echo "$sum + $time" | bc -l) | |
| 23 (( count++ )) | |
| 24 done | |
| 25 average=$(echo "$sum / $count" | bc -l) | |
| 26 #echo "count=$count, sum=$sum, average=$average" | |
| 27 | |
| 28 #go over the numbers, take the difference from the average and squart, then sq
uare root / count. | |
| 29 sum_dev=0 | |
| 30 for time in $2 | |
| 31 do | |
| 32 step=$(echo "$time - $average" | bc -l) | |
| 33 sum_dev=$(echo "$sum_dev + $step^2" | bc -l) | |
| 34 done | |
| 35 | |
| 36 step=$(echo "$sum_dev / $count" | bc -l) | |
| 37 OUT="sqrt(${step})" | |
| 38 standard_dev=$(echo $OUT | bc -l | sed 's/\([0-9]*\.[0-9][0-9]\)[0-9]*/\1/') | |
| 39 average=$(echo $average | sed 's/\([0-9]*\.[0-9][0-9]\)[0-9]*/\1/') | |
| 40 AVERAGE=$average | |
| 41 STDEV=$standard_dev | |
| 42 COUNT=$count | |
| 43 } | |
| 44 | |
| 45 function do_math() { | |
| 46 do_math_return "$1" "$2" | |
| 47 echo "$1: average: $AVERAGE stdev: $STDEV count: $COUNT" | |
| 48 } | |
| 49 | |
| 50 function sample_file_return() { | |
| 51 TIMES=$(sed -n "s/$2\S*\s*:\s*\(\([0-9]*\)\(\.[0-9]*\)\?\)/\1/p" $3) | |
| 52 do_math_return "$1" "$TIMES" | |
| 53 SAMPLE_LINE="$1: average: $AVERAGE stdev: $STDEV count: $COUNT" | |
| 54 } | |
| 55 | |
| 56 function sample_file() { | |
| 57 TIMES=$(sed -n "s/$2\S*\s*:\s*\(\([0-9]*\)\(\.[0-9]*\)\?\)/\1/p" $3) | |
| 58 do_math "$1" "$TIMES" | |
| 59 } | |
| OLD | NEW |