Skip to content

Instantly share code, notes, and snippets.

@tylermilner
Created May 1, 2020 15:34
Show Gist options
  • Save tylermilner/3517e09ad38f481bfab4e66c2f0e8708 to your computer and use it in GitHub Desktop.
Save tylermilner/3517e09ad38f481bfab4e66c2f0e8708 to your computer and use it in GitHub Desktop.
A simple Bash script to generate an average build time for your iOS project. Replace with your project's workspace and scheme before use.
#!/bin/bash
# Workspace and scheme parameters for the project
workspace="ProjectWorkspace.xcworkspace" # TODO: Replace with your project's workspace
scheme="ProjectScheme" # TODO: Replace with your project's scheme
# The number of times to build the project
numRuns=3
# Abort the process if any of the commands in this script fail
set -e
# Variable to hold the total build duration over all runs
totalBuildTime=0
echo "Building project $numRuns times..."
# Perform the build n times
for ((i=1;i<=numRuns;i++))
do
echo "Starting build $i..."
# Clean the project first
echo "Cleaning project before starting the build..."
xcodebuild \
-workspace "$workspace" \
-scheme "$scheme" \
clean
echo "Clean complete."
# Get the start time of the build
start=`date +%s`
echo "Starting build $i at $start..."
# Build the project
xcodebuild \
-workspace "$workspace" \
-scheme "$scheme" \
# Get the end time of the build
end=`date +%s`
echo "Build $i ended at $end."
# Calculate the time it took to build the project
runtime=$((end-start))
echo "Build $i took $runtime seconds."
totalBuildTime=$((totalBuildTime+runtime))
done
# Calculate the average build time
averageBuildTime=$((totalBuildTime/numRuns))
echo "Average build time was $averageBuildTime seconds."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment