aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-04-29 01:13:52 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2016-04-29 01:13:52 -0400
commit5ef23bb5af757f84c89ba329ebe5e4fe502205a7 (patch)
tree12eb713ff7dc577a332ee60470d14ab10ab73f43
parent3f2b9430c2de4641fdb1126d3d4e1556de1504b6 (diff)
downloadcbt-5ef23bb5af757f84c89ba329ebe5e4fe502205a7.tar.gz
cbt-5ef23bb5af757f84c89ba329ebe5e4fe502205a7.tar.bz2
cbt-5ef23bb5af757f84c89ba329ebe5e4fe502205a7.zip
remove required gdate dependency
-rw-r--r--DEVELOPER_GUIDE.txt1
-rwxr-xr-xcbt31
2 files changed, 22 insertions, 10 deletions
diff --git a/DEVELOPER_GUIDE.txt b/DEVELOPER_GUIDE.txt
index 5869257..b878a72 100644
--- a/DEVELOPER_GUIDE.txt
+++ b/DEVELOPER_GUIDE.txt
@@ -38,3 +38,4 @@ We strongly suggest well polished PRs, but don't want to stall improvements
by discussions about minor flaws. As long as the PR does not break anything and
improves the product, we should merge it, polishing remaining things afterwards.
+On OSX `brew install coreutils` to have gdate and get nanosecond timings during bash script.
diff --git a/cbt b/cbt
index 5d02917..0c5eaca 100755
--- a/cbt
+++ b/cbt
@@ -8,12 +8,27 @@
# - reduction of dependencies
# - performance improvements
-start_seconds=$(gdate +"%s")
-start_nanos=1$(gdate +"%N")
+seconds() {
+ date +"%s"
+}
+
+nanos() {
+ n=$(date +"%N")
+ if [ "$n" = "N" ]; then
+ n=$(gdate +"%N" 2>/dev/null)
+ fi
+ if [ "$n" = "" ]; then
+ n="0"
+ fi
+ echo $n
+}
+
+start_seconds=$(seconds)
+start_nanos=1$(nanos)
time_taken() {
- i=$(( $(gdate +"%s") - start_seconds ))
- n=$(( $(( 1$(gdate +"%N") - start_nanos )) / 1000000 ))
+ i=$(( $(seconds) - start_seconds ))
+ n=$(( $(( 1$(nanos) - start_nanos )) / 1000000 ))
if [[ ( "$n" < 0 ) ]]; then
i=$(( i-1 ))
n=$(( n+1000 ))
@@ -33,12 +48,8 @@ log () {
shift
done
if [ $enabled -eq 0 ]; then
- which gdate 2>&1 > /dev/null
- gdate_installed=$?
- if [ $gdate_installed -eq 0 ]; then
- delta=$(time_taken)
- echo "[$delta] $msg" 1>&2
- fi
+ delta=$(time_taken)
+ echo "[$delta] $msg" 1>&2
fi
}