Skip to content

Instantly share code, notes, and snippets.

@theapache64
Last active August 18, 2022 13:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theapache64/59076f10ef99e8eec9188c59495e8e43 to your computer and use it in GitHub Desktop.
Save theapache64/59076f10ef99e8eec9188c59495e8e43 to your computer and use it in GitHub Desktop.
To measure average Activity startup time
# To measure lauch time
fun launchTime(){
# Config
LAUNCH_COUNT=10
REGEX='TotalTime: (\d+)'
# The two params are configurable via argument
DEFAULT_PACKAGE_NAME='com.your.packagename'
DEFAULT_ACTIVITY_NAME='com.my.packagename.MainActivity'
PACKAGE_NAME="${1:-$DEFAULT_PACKAGE_NAME}"
ACTIVITY_NAME="${2:-$DEFAULT_ACTIVITY_NAME}"
echo "Initiating launch time measurement for $PACKAGE_NAME/$ACTIVITY_NAME (launhCount=$LAUNCH_COUNT)"
# Launching
TIME_SUM=0
for ((i = 0 ; i < LAUNCH_COUNT ; i++)); do
TIME=$(
adb shell am force-stop $PACKAGE_NAME &&
adb shell am start-activity -W -n $PACKAGE_NAME/$ACTIVITY_NAME | pcregrep -o1 "$REGEX"
)
TIME_SUM=$(($TIME_SUM + $TIME))
echo "launch $(($i+1)) -> launch time is $TIME ms"
done
# Measuring
AVG=$(($TIME_SUM / $LAUNCH_COUNT))
echo "Average is $AVG ms"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment