2017-03-31 30 views
2

我知道你可以使用這樣的事情每個獨立的功能的編譯時間:如何獲取命令運行所需的總時間?

xcodebuild -workspace App.xcworkspace -scheme App clean build OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" | grep .[0-9]ms | grep -v ^0.[0-9]ms | sort -nr > culprits.txt 

或本

defaults write com.apple.dt.Xcode ShowBuildOperationDuration -bool YES 

,但我怎樣才能在命令行打印出來的總建造時間?

回答

2

稍微更有效的方法 - 在這裏我們稱之爲date只有兩次:

#!/bin/bash 
start_time=$(date +%s) 
# xcode command here 
end_time=$(date +%s) 
printf 'Elapsed time is %d seconds\n' $((end_time - start_time)) 

這是可能的獲取當前時間即使不分叉,用printf

#!/bin/bash 
printf -v start_time '%(%s)T' -1 
# xcode command here 
printf -v end_time '%(%s)T' -1 
printf 'Elapsed time is %d seconds\n' $((end_time - start_time)) 
1

我想最簡單的方法是運行像這樣:

#!/bin/sh 

COMPILE_START=`date` 
# your compile commands 
COMPILE_END=`date` 
printf "%s\n" $(($(date -d "$COMPILE_END" "+%s") \ 
       - $(date -d "$COMPILE_START" "+%s"))) 
1

假設它是bash命令:

startTime=$(date +%s) 

#Your commands 

finishTime=$(date +%s) 
timeElapsed=$((finishTime - startTime)) 
minute=$((timeElapsed/60)) 
sec=$((timeElapsed % 60)) 
echo Total time: $minute min $sec sec