Skip to content

Instantly share code, notes, and snippets.

@Joshix-1
Created July 23, 2021 22:39
Show Gist options
  • Save Joshix-1/aa3be8f71f283ff9b022add03c849d47 to your computer and use it in GitHub Desktop.
Save Joshix-1/aa3be8f71f283ff9b022add03c849d47 to your computer and use it in GitHub Desktop.
#!/bin/sh
echo "Command: $1"
echo "Run count: $2"
CURRENT_TIME=$(date +%s)
I=0 # counter counts up to $2 - 1
TIME=0 # the whole time in ns
while [ "$I" != "$2" ]
do
DATE1=$(date +%s%N)
VAL=$($1)
DATE2=$(date +%s%N)
TIME="$(expr $(expr $DATE2 - $DATE1) + $TIME)"
I=$(expr $I + 1)
done
echo "Time since start: $(expr $(date +%s) - $CURRENT_TIME) s"
echo "Time in command: $(expr $TIME / 1000000000).$(expr $TIME % 1000000000) s"
TIME_PER_RUN=$(expr $TIME / $2) # ns
echo "Time per run: $(expr $TIME_PER_RUN / 1000000).$(expr $TIME_PER_RUN % 1000000) ms"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment