The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 414     Votes:  2 
Tags: command-line   monitoring  
Link: 🔍 See Original Answer on Ask Ubuntu 🔗

Title: how to time a certain part of an executable?
ID: /2018/05/16/how-to-time-a-certain-part-of-an-executable_
Created: May 16, 2018    Edited:  May 16, 2018
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false

The easiest way is to put the time command in front of the command you are running. For example:

$ time locate display-auto
/home/rick/Pictures/display-auto-brightness conky.png
/home/rick/Pictures/display-auto-brightness systray.png
/home/rick/Pictures/display-auto-brightness-config 1.png
/home/rick/Pictures/ps display-auto-brightness.png

real	0m0.826s
user	0m0.803s
sys 	0m0.016s

We are using the locate command to find all the filenames with display-auto in the names. Simply insert the time command in front of the command.

Getting time for portion of script

You can use the $SECONDS variable inside your script to get the time for a portion of it. For example:

/bin/egrep -v "^#|^$" $BLOCKEDIPS_XS | while IFS= read -r ip
    # Append everything to droplist
    $IPTABLES -A droplist -i eth0 -s $ip -j LOG --log-prefix " Drop IP List blockxs "
    $IPTABLES -A droplist -i eth0 -s $ip -j DROP
timer stops, shows elapsed time
echo "Total time to block IPs: $BlockTime Seconds"

In this code the SECONDS is reset to zero and then obtained after a lengthy process occurs.

⇧ Bash script to run python script for all images in all subdirectories Nautilus not showing mounted drives in side bar  ⇩