Created
February 28, 2025 15:07
-
-
Save Souheil-Yazji/de33a39e8e5335929797b347fbc75770 to your computer and use it in GitHub Desktop.
Measure Bash cmd runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
your_command="ls -l" # --- UPDATE COMMAND HERE --- | |
start_time=$(date +%s) | |
eval $your_command | |
end_time=$(date +%s) | |
# Calculate the elapsed time in seconds | |
elapsed_time=$((end_time - start_time)) | |
# Convert elapsed time to hh:mm:ss format | |
hours=$((elapsed_time / 3600)) | |
minutes=$(( (elapsed_time % 3600) / 60 )) | |
seconds=$((elapsed_time % 60)) | |
# Write elapsed time and command to a file | |
echo "Command: $your_command" >> elapsed_time.log | |
echo "Elapsed time: $hours:$minutes:$seconds" >> elapsed_time.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment