I'm writing a triple-loop program to measure execution time and memory use of some programs. Basically I have a small program that runs too fast to gather meaningful data so I am running it in a shell script many times and measuring that total time. To gather accurate data I need to subtract the execution time and memory overhead of the empty loop. I also want to subtract the time and memory it takes to seed the program with random data.
This snippet has all the data I want to gather from /usr/bin/time:
Code:
/usr/bin/time --append --output="$HOME/timinglogs/fileName" --format="Program:%C\nRealTime:%e\t\t SystemTime:%S\tUserTime:%U\nAvgTotalMem=%KKBs\t NumSwaps:%W\n" progamName
This is what I have right now:
Code:
#!/bin/bash
#first run the program n times and time that
#then run the seeder n times and time that
#then run an empty function loop n times and time that
#subtract empty function loop from both times
#subtract seed time from run time
##in all these short functions
##$1 is how many times to loop
##$2 is the program to run
run_program() {
i=0
while [ $i -lt $1 ]; do
./$2 #program name
let i=$i+1
done
}
run_seeder() {
i=0
while [ $i -lt $1 ]; do
./$2 #seeder name
let i=$i+1
done
}
empty_loop(){
i=0
while [ $i -lt $1]; do
let i=$i+1
done
}
my_time () {
#call time on run_program
#call time on run_seeder
#call time on empty loop
#subtract them
#log result
}
My biggest problem (so far) is figuring out a way to automate the subtraction of these numbers.