Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- avg_time() {
- #
- # usage: avg_time n command ...
- #
- n=$1; shift
- (($# > 0)) || return # bail if no command given
- for ((i = 0; i < n; i++)); do
- { time -p "$@" &>/dev/null; } 2>&1 # ignore the output of the command
- # but collect time's output in stdout
- done | awk '
- /real/ { real = real + $2; nr++ }
- /user/ { user = user + $2; nu++ }
- /sys/ { sys = sys + $2; ns++}
- END {
- if (nr>0) printf("%f,%f,%f\n", real/nr, user/nr, sys/nr);
- }'
- }
- # Generate base file
- dd if=/dev/random of=base.bin bs=1m count=1000 >& /dev/null
- # Number of trials per file for compilation
- TRIALS=3
- for i in `seq 1 50`; do
- # Copy small subsection
- dd if=base.bin of=random.bin bs=1m count="$i" >& /dev/null
- # Convert it to a C file and append it to the template
- xxd -i random.bin | cat - template.c > benchmark.c
- printf "$i,"
- avg_time $TRIALS gcc -c benchmark.c
- done
- ## template.c
- # #include <stdio.h>
- # int main() {
- # char mod = 0;
- # for (int i=0; i<random_bin_len; ++i) {
- # mod += random_bin[i];
- # }
- # printf("%d", mod);
- # return 0;
- # }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement