Skip to main content
InterviewHubPRO
Section Overview
Q34

Question 34 of 50

Part 3: Advanced Text Processing & Production Internals (Senior / Lead)

68%
Bash & Shell Scripting (50 Qs)•Part 3: Advanced Text Processing & Production Internals (Senior / Lead)

How do you measure script execution time in milliseconds?

senior LevelCode Examplebash-shellAdvanced Text Processing

In Simple Words:

  • In Bash 5.0+, use the built-in variable $EPOCHREALTIME (returns microsecond-precision epoch timestamp):
bash
start_time=$EPOCHREALTIME
sleep 0.5
end_time=$EPOCHREALTIME

# Calculate delta using awk or bc:
elapsed=$(awk "BEGIN { print ($end_time - $start_time) * 1000 }")
echo "Execution time: ${elapsed}ms"