-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbenchmark
More file actions
executable file
·34 lines (27 loc) · 817 Bytes
/
benchmark
File metadata and controls
executable file
·34 lines (27 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
#
# @author Stephen J. Carnam
# @license GNU GENERAL PUBLIC LICENSE Version 2
# @link https://steveorevo.com
#
# Check if a command is provided
if [ -z "$1" ]; then
echo "Usage: benchmark <command>"
exit 1
fi
# Capture the start time in nanoseconds
start_time=$(date +%s%N)
# Run the provided command
"$@"
# Capture the end time in nanoseconds
end_time=$(date +%s%N)
# Calculate the elapsed time in seconds with fractional seconds
elapsed_time=$(echo "scale=6; ($end_time - $start_time) / 1000000000" | bc)
# Format the elapsed time
minutes=$(echo "$elapsed_time / 60" | bc)
seconds=$(echo "$elapsed_time % 60" | bc)
if (( $(echo "$minutes > 0" | bc -l) )); then
printf "Time taken: %d minutes and %.6f seconds\n" "$minutes" "$seconds"
else
printf "Time taken: %.6f seconds\n" "$seconds"
fi