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.
Prerequisites
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.
cal_runtime.sh
clear
ls -l
date
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.
0 Comments