Skip to content

Instantly share code, notes, and snippets.

@Souheil-Yazji
Created February 28, 2025 15:07
Show Gist options
  • Save Souheil-Yazji/de33a39e8e5335929797b347fbc75770 to your computer and use it in GitHub Desktop.
Save Souheil-Yazji/de33a39e8e5335929797b347fbc75770 to your computer and use it in GitHub Desktop.
Measure Bash cmd runtime
#!/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