The following bash code might come handy for those of you who want to benchmark how long does a program runs.
In the following example the assumption is that you want to pass along two parameters for your program to run properly.
A time will be recorded at the beginning and at the end of the execution. And a time diff, the processing time, will be reported in seconds.
#!/bin/bash
##################################################
# Benchmark the processing time when a program
# executes with two required parameters: parameter1 parameter2
##################################################
if [[ $1 = "" || $2 = "" ]]; then
echo "Usage: `basename $0` parameter1 parameter2"
else
_start_time=`date +%s`
_parameter1=$1
_parameter2=$2
### YOUR COMMAND HERE WITH parameter1 AND parameter2 ###
_end_time=`date +%s`
_processing_time=$((_end_time-_start_time))
echo "Source File: $_parameter1"
echo "Destination File: $_parameter2"
echo "Start time: $_start_time"
echo "End time: $_end_time"
echo "Processing time is: $_processing_time"
fi
Leave a Reply