This article is an automatic translation.
Execution Time Analysis - Christopher Villamarín Blog
Christopher Alexander Villamarín Pila
GitHub
This project is designed to analyze the execution times of commands or programs in Unix systems, calculating key statistics such as the average and standard deviation of real, user, and system time.
Project Description
The program uses a combination of Bash and AWK to collect execution time data of a command over multiple iterations. These times are analyzed to provide detailed information about:
- Real time: The total time the execution took.
- User time: The time the processor spent executing user instructions.
- System time: The time spent by the operating system kernel.
How it works
- Collect data:
A Bash script executes the provided command 10 times using
/usr/bin/time, and saves the results to a temporary file named/tmp/exetime. - Data processing:
An AWK script (
calc.awk) reads the results file and calculates:- Average of real, user, and system time.
- Standard deviation of each time.
- Print statistics: The results are printed in a readable format with information about the times and their statistics.
Expected Results
When running the program, you get a detailed breakdown of each command iteration, along with the average and standard deviation of the execution times:
Data:-------------------------real user sys2.3 1.2 0.42.5 1.3 0.5-------------------------Average:real 2.4user 1.25sys 0.45Standard deviation:real 0.1user 0.05sys 0.05
Requirements
-
Install the
timecommand:
For Debian/Ubuntu systems:sudo apt-get install time - A Unix environment compatible with Bash and AWK.
How to run
-
Save the AWK file (
calc.awk) on your system. -
Run the Bash script with the command you want to analyze:
bash speedtest.sh [command]
-
Check the statistics calculated by AWK:
awk -f calc.awk /tmp/exetime