Calculating and reducing the runtime of a script

Update on:
Oct 3, 2021

In this article, we are going to learn how to calculate and reduce the script’s runtime. A simple time command will help in calculating the execution time.


Besides having a terminal open, make sure you have the necessary scripts present in your system.

Write script

Now, we will write a simple script that contains a few commands, and then, using the time command, we will get the runtime of that script. Create a script cal_runtime.sh and write the following code in it.


ls -l 
sudo apt install python3

How script works

Now, we have written a script cal_runtime.sh and four commands in that script: clear, ls, date, and a python3 installation command. Run your script as follows:

$ time bash cal_runtime.sh

After the execution, you will get the runtime of the script at the bottom of your output.

Related Posts

Creating a config file and using it in tandem with your scripts

In this article, we are going to create a config file and use it in our shell script.PrerequisitesBesides having a terminal open, you need basic knowledge of creating scripts and config files.Write scriptNow, we are going to create a script and config file. The...

Using Bash to monitor battery life and optimize it

In this article, we will learn about the TLP Linux tool. TLP is a command-line tool; it is used for power management and will optimize the battery life.PrerequisitesBesides having a Terminal open, you need to ensure that you have TLP installed on your system.How to do...

Creating a simple NAT and DMZ firewall using bash script

In this article, we will create a simple NAT firewall with DMZ using iptables.PrerequisitesBesides having a Terminal open, you need to ensure that iptables is installed in your machine.Write scriptWe will write a script to set up a DMZ using iptables. Create...

Making a simple IRC chat bot logger using bash script

In this article, we will make a simple bot logger. This script will log a few channels as well as handle the pings.PrerequisitesBesides having a Terminal open, you need to have basic knowledge of IRC.Write script:Now, we will write a script for an IRC logging bot....

Follow Us

Our Communities

More on BASH

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!



Submit a Comment

Your email address will not be published.

2 × 1 =