Guide to Using XcodeBenchmark and Benchmarking XCode Builds
In building a mobile application, many factors can dominate the development process. For most teams, a focus on speed and quality is the primary directive during the majority of the process, leaving aspects like efficiency and robustness for a later stage. For others, however, ensuring that the development process is efficient and performant is a crucial component of a successful product.
There are many ways to identify and diagnose issues with the performance of your workflow and how it affects your build times. For example, you can take a more global approach and examine the raw performance of your computer. Or you can go more granular and work on the individual components in Xcode build workflow to modify your code. You could even use a combination of both.
If you want to start with the former, one of the best tools to measure the performance of your computer is XcodeBenchmark.
In this post, we'll talk about performance in iOS development and help you leverage tools like XcodeBenchmark and other third-party tools such as XcodeBuildAnalyzer, XcodeServer SDK, and Xcode-build-times to improve your team's development pipeline.
Let's jump right in.
What Is XcodeBenchmark?
As mentioned before, XcodeBenchmark is a command line tool that measures the performance of your development station. Dev and YouTuber Max Tech developed it as a tool to help measure the performance of different Apple products. And it does so by measuring the time it takes to build and run a heavy Xcode project, and the time it takes to execute various common Xcode commands.
XcodeBenchmark includes 42 popular CocoaPods libraries and 70+ dependencies, making it a good representation of a complex and heavy project.
By running the XcodeBenchmark, you can have a clearer picture of your computer’s raw power and identify if your development station is adequate for your needs.
How to Use XcodeBenchmark
To use XcodeBenchmark, you must first download it from their Git repository. Then, you must open the Terminal app and use the following command:
Keep in mind that there are some steps that you should take before starting any benchmark so that you can get the most accurate reading.
- Disconnect the network cable and turn off the WiFi.
- Make sure to disable all software running at startup.
- Go to System Preferences > Users and Groups > User > Login Items.
- Empty the list.
- Update battery settings.
- Go to System Preferences > Battery > Battery/Power Adapter > Turn the display off and set 15 minutes.
- Reboot and cool down your Mac.
- Connect to the power adapter if you're using a MacBook.
When XcodeBenchmark completes, it'll present you with this information, summarizing the spec information of your device and how it performed concisely. You can choose to upload these results for others to see.
The results indicate relative Xcode performance in a best-case scenario compared to other Macs operating under comparable conditions. This is a good way to confirm that your development workstation can handle the projects you want to work on.
However, this is only part of the picture, as your bottleneck might not be your computer but your workflow.
Benchmarking Xcode Builds
Now, what if you already checked that your computer has enough horsepower, but you still need better build times on your projects?
There are several ways to benchmark Xcode builds, depending on what you want to measure and optimize: Xcode's built-in performance measurement tools, the command line, and third-party tools.
Using Xcode's Built-In Performance Measurement Tools
Xcode includes several built-in performance measurement tools that can help you identify performance bottlenecks in your code. You can access these tools via the "Product" menu in Xcode.
The Time Profiler is one of the most commonly used performance measurement tools. It helps you understand how your application uses CPU resources and can identify which parts of your code take the most time to execute.
The Time Profiler collects data about your application's performance as it runs and then presents it in an easy-to-read format.
The Memory Graph Debugger is another helpful tool that allows you to visualize your application's memory usage. In addition, the Memory Graph Debugger can help you identify memory leaks and other memory-related issues.
The Energy Log Navigator allows you to track the energy usage of your application and identify areas where you can optimize energy consumption.
Using the Command Line
You can use the xcodebuild command line tool to build and measure the performance of your projects. The xcodebuild tool allows you to build, test, and archive your projects from the command line.
To display the build settings for a project, you can use the -showBuildSettings option. For example, the following command will display the build settings for a project named "MyProject":
To build a project and measure its performance, you can use the -configuration option to specify the configuration (e.g., debug or release). For example, the following command will build a project named "MyProject" in the release configuration:
You can also use the -destination option to specify the destination for the build. For example, the following command will build a project named "MyProject" for an iOS device:
Using Third-Party Tools
Several third-party tools, such as XcodeBuildAnalyzer, XcodeServer SDK, and Xcode-build-times, can help you benchmark Xcode builds. These tools can provide more advanced features and better visualization of the build performance data.
- XcodeBuildAnalyzer is a command line tool that generates a report of the build times for an Xcode project. It can help you understand how long it takes to build each target and each file in your project.
- XcodeServer SDK is a framework that allows you to integrate Xcode's build and test functionality into your continuous integration systems. This can be useful if you want to automate your builds and tests and consistently measure their performance.
- Xcode-build-times is a command line tool that measures the time to build an Xcode project. You can use this tool to measure the performance of different versions of Xcode and compare them.
Other Tips for Optimizing Build Times
In addition to using benchmarking tools, there are a few other things you can do to optimize your build times:
- Use Xcode's build system settings to optimize your build process. For example, you can use the "Parallelize Build" setting to build multiple targets or build phases simultaneously, or you can use the "Incremental Build" setting only to rebuild the parts of your project that have changed since the last build.
- Keep your Xcode project organized and well-structured. A well-organized project with a clear file hierarchy and logical groupings of files can help improve build times.
- Use a tool like Xcode-cache-cleaner to clean up Xcode's build cache. Over time, the build cache can become cluttered with unnecessary files, slowing down your build times. Xcode-cache-cleaner can help clean up the build cache and improve build times.
- Use a tool like xcodebuild-wrapper to improve the output of Xcode's build system. Xcodebuild-wrapper can help you see more detailed output from Xcode's build system, which can help you identify bottlenecks in your build process and optimize your build times.
When benchmarking Xcode builds, it's essential to measure the performance of your builds consistently. Therefore, you should use the same build settings and the same version of Xcode for all your builds. This will allow you to compare the performance of your builds over time and identify any changes that may be affecting performance.
In addition, you should focus on optimizing your code's performance rather than the build process's performance. You can do this by using the appropriate data structures and algorithms, avoiding unnecessary computations and memory allocation, and using caching and other performance optimization techniques.
Another critical thing to remember is that performance optimization is not a one-time task. Instead, it's a continuous process. Therefore, you should monitor performance regularly and make adjustments as needed.
Besides optimizing performance, it's also essential to ensure that your code is robust and bug-free. If this is important for you and you don't have the time or resources to ensure this, check out Waldo's extensive toolbox for UI testing to ensure your code is secure and resilient. Even for non-developers, it's incredibly accessible and doesn't require any code.
A free trial is available here.
In summary, there are several ways to benchmark Xcode builds, including using Xcode's built-in performance measurement tools, the command line, and third-party tools.
However, it's essential to measure the performance of your builds consistently and focus on optimizing the performance of your code to ensure efficient builds.