我知道您可以使用如下方法获取每个函数的编译时间:
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
但是我怎样才能在命令行中打印出总构建时间呢?
最佳答案
一种稍微更有效的方法 - 这里我们只调用 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))
即使没有 fork ,也可以通过 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))
关于bash - 如何获得命令运行所需的总时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43149568/