Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############################################################################################################################
- # stopwatch v1.5 - simple tool to measure time between a certain start & end point #
- # Handshake: #
- # $SW_PREC sets the precision level. Higher values result in larger, more precise measurements (default: 3) #
- # Usage: #
- # Simply call SW_TRIGGER() to start measuring. If called the first time, it sets the current time as start time. When #
- # called every other time, it calculates and shows the difference between start and current time and also sets the current #
- # time as new start time. Note that the function itself takes about 10-30ms of processing time. Prints results to stdout. #
- ############################################################################################################################
- SW_START=
- SW_TRIGGER(){
- [ -z "${SW_PREC##*[!0-9]*}" ] || [ $SW_PREC -lt 3 ] && SW_PREC=3
- SW_MULT=1$(printf %"$SW_PREC"s | tr " " "0")
- SW_TIME=$(date +%s:%"$SW_PREC"N | awk -F ':' '{print ($1*'$SW_MULT')+$2}')
- if [ -n "$SW_START" ]; then
- SW_DIFF=$(($(date +%s:%"$SW_PREC"N | awk -F ':' '{print ($1*'$SW_MULT')+$2}')-$SW_START))
- [ $SW_PREC -gt 3 ] && SW_DIFF=$(printf $SW_DIFF | awk '{printf("%."SW_DP"f\n",$1/10^SW_DP)}' SW_DP=$(($SW_PREC-3)))
- echo $SW_DIFF"ms"
- fi
- SW_START=$SW_TIME
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement