-
-
Save Puneeth-n/b5944b96a3f854cebf9f to your computer and use it in GitHub Desktop.
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 | |
function showHelp { | |
version=0.0.1 | |
versionDate="2014-07-07" | |
echo "$0 - tic/toc timer pair | |
Usage: $0 [id] Stores initial time (w/optional id marker) | |
$0 [-u|--unique] Creates and returns unique id | |
Using optional ID is recommended, as it allows simulatenous usage. | |
Notes: | |
ttoc [id] (displays delta time since ttic was called) | |
Temporary timer file is stored at /tmp/.ttic.[ID.]time | |
Example | |
# Global timer (not recommended) | |
ttic && (do work) && ttoc | |
# Using FooBar as id | |
ttic FooBar && (do work) && ttoc FooBar | |
# Using a randomly generated id | |
id=\$(ttic -u) && (do work) && ttoc \$id | |
Mainted at: https://gist.github.com/swarminglogic/87adb0bd0850d76ba09f | |
Author: Roald Fernandez ([email protected]) | |
Version: $version ($versionDate) | |
License: CC-zero (public domain) | |
" | |
exit $1 | |
} | |
while test $# -gt 0; do | |
case "$1" in | |
-h|--help) | |
showHelp 0 | |
;; | |
-u|--unique) | |
shift | |
hasId=yes | |
isGenerated=yes | |
id=$(tr -dc "[:alpha:]" < /dev/urandom | head -c 8) | |
;; | |
*) | |
hasId=yes | |
id=$1 | |
shift | |
break | |
;; | |
esac | |
done | |
if [[ $hasId ]] ; then | |
tmpfile=/tmp/.ttic.${id}.time | |
if [[ $isGenerated ]] ; then | |
echo $id | |
fi | |
else | |
tmpfile=/tmp/.ttic.time | |
fi | |
echo $(($(date +%s%N)/1000000)) > $tmpfile |
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 | |
function showHelp { | |
version=0.0.1 | |
versionDate="2014-07-07" | |
echo "$0 - tic/toc timer pair | |
Usage: $0 [id] | |
Stores initial time (w/optional id marker) | |
Notes: | |
ttic [id] (used for marking initial time) | |
Temporary timer file is stored at /tmp/.ttic.[ID.]time | |
Example | |
# Global timer (not recommended) | |
ttic && (do work) && ttoc | |
# Using FooBar as id | |
ttic FooBar && (do work) && ttoc FooBar | |
# Using a randomly generated id | |
id=\$(ttic -u) && (do work) && ttoc \$id | |
Mainted at: https://gist.github.com/swarminglogic/87adb0bd0850d76ba09f | |
Author: Roald Fernandez ([email protected]) | |
Version: $version ($versionDate) | |
License: CC-zero (public domain) | |
" | |
exit $1 | |
} | |
while test $# -gt 0; do | |
case "$1" in | |
-h|--help) | |
showHelp 0 | |
;; | |
*) | |
hasId=yes | |
id=$1 | |
shift | |
break | |
;; | |
esac | |
done | |
if [[ $hasId ]] ; then | |
tmpfile=/tmp/.ttic.${id}.time | |
else | |
tmpfile=/tmp/.ttic.time | |
fi | |
if [ ! -e $tmpfile ] ; then | |
echo "Did not find initalized time file. Run ttic with same id before ttoc!" | |
exit 1 | |
fi | |
tic=`cat $tmpfile` | |
toc=$(($(date +%s%N)/1000000)) | |
delta=$(($toc - $tic)) | |
LC_NUMERIC=C LC_COLLATE=C | |
printf '%g\n' $(bc <<< "scale=3; ${delta}/1000") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment