Created
November 9, 2014 02:42
-
-
Save lamchau/b432a8c303bb9f0fdd32 to your computer and use it in GitHub Desktop.
Homework assistance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| clear | |
| BORDER=$(printf '=%.0s' {1..80})\\n | |
| HEADER="%-10s %8s %-10s %24s %11s\n" | |
| FORMAT="%-10s %8d %-10s %11.2f\n" | |
| WIDTH=150 | |
| # not defined, what should this be? | |
| # DIVIDER="DIVIDER" | |
| OUTPUT_FILENAME=experimentation.csv | |
| # delete the file if it exists | |
| [ -f "$OUTPUT_FILENAME" ] && rm $OUTPUT_FILENAME | |
| # write header to file | |
| printf "$BORDER" | tee -a $OUTPUT_FILENAME | |
| printf "$HEADER" "SORT NUM" "2^n" "Output" "Elapsed Time" | tee -a $OUTPUT_FILENAME | |
| printf "%$WIDTH.${WIDTH}s\n" "$DIVIDER" | tee -a $OUTPUT_FILENAME | |
| for x in {1..5}; do | |
| for n in {4..12}; do | |
| exponent=$((2**n)) | |
| # save output from 'my_sort' so it can be written to file | |
| result="$(./my_sort $x $n)" | |
| REPLACE_ME=$(((RANDOM % 10) + 100)) | |
| printf "$FORMAT" "$x" "$n" "$result" "$REPLACE_ME" | tee -a $OUTPUT_FILENAME | |
| done | |
| done | |
| # Example output: | |
| # SORT NUM 2^n Output Elapsed Time | |
| # 1 4 output-from-process 108.00 | |
| # 1 5 output-from-process 107.00 | |
| # 1 6 output-from-process 101.00 | |
| # 1 7 output-from-process 105.00 | |
| # 1 8 output-from-process 106.00 | |
| # 1 9 output-from-process 106.00 | |
| # 1 10 output-from-process 101.00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment