-
Notifications
You must be signed in to change notification settings - Fork 2
/
osp
executable file
·48 lines (37 loc) · 1.61 KB
/
osp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# initialize sum variables
sum_output=0
sum_output_opt=0
total_iterations=${it:-5}
opt=${opt:-1}
break_long=${break_long:-0}
echo "Test output_code_opt${opt}.py"
# warmup
printf "\rProgress: [%-50s] %d%%" $(printf '%.0s#' $(seq 1 $((0*50/total_iterations)))) $((0*100/total_iterations))
# Start the progress bar
for i in $(seq 1 $total_iterations); do
# run output_code.py, add output to sum_output
output=$(python output_code.py)
sum_output=$(echo "$sum_output + $output" | bc -l)
# run output_code_opt.py, add output to sum_output_opt
output_opt=$(python output_code_opt${opt}.py)
sum_output_opt=$(echo "$sum_output_opt + $output_opt" | bc -l)
# echo "Output: $output, Output_opt: $output_opt"
# echo "Sum_output: $sum_output, Sum_output_opt: $sum_output_opt"
# update the progress bar
printf "\rProgress: [%-50s] %d%%" $(printf '%.0s#' $(seq 1 $((i*50/total_iterations)))) $((i*100/total_iterations))
# if output is larger than 1, break_long is not 0, and i is larger than break_long, break
if (( $(echo "$output > 1" | bc -l) )) && (( $break_long != 0 )) && (( $i > $break_long )); then
echo "break after iteration $i since the iteration is too long"
break
fi
done
# calculate averages
avg_output=$(echo "scale=6; $sum_output / ${total_iterations}" | bc -l)
avg_output_opt=$(echo "scale=6; $sum_output_opt / ${total_iterations}" | bc -l)
# calculate speedup
speedup=$(echo "scale=6; $avg_output / $avg_output_opt" | bc -l)
# print speedup
echo -e "\nAverage output: $avg_output"
echo -e "Average output_opt: $avg_output_opt"
echo -e "Speedup: $speedup"