XCMetrics is a reference implementation to accurately measure performance metrics of your code using Unit and UI tests. It provides detailed examples covering both old( i.e. XCTPerformanceMetric) & the new(i.e. XCTMetric) performance-testing system. It also fixes bugs/peculiarities in the XCTest performance APIs with runtime hooks(i.e. Monkey Patching), making it more stable & consistent.
Performance testing using XCTest framework(i.e. XCTMetric confirming types) have some rough edges i.e. bugs/peculiarities. This project aims to fix all those bugs in the performance APIs using Swizzling, making a consistent experience on both iOS 13 & 14. Here's the list of open issues and radars:
- Default Launch Performance Test Crashes Occasionally
- Getting error measuring signpost metrics in XCUITests
- XCTests crash randomly in parallel testing
- XCTOSSignpostMetric doesn’t detect signposts logged by static library
- Lost connection to test manager service
- Lastly, Lack of performance tests documentation
Performance tests helps in identifying the impact of your code in terms of various metrics like CPU, Clock, Memory, Storage, Signpost, AppLaunch and more. Capturing performance metrics in your CI pipeline helps in identifying performance bottlenecks and regressions produced by your code over-time. If your performance metrics are going off, then Instruments can help in analysing the root cause.
Detailed examples of performance testing covering the usage of following metrics:
XCTCPUMetricto record information about CPU activity during a performance test.XCTClockMetricto record the time that elapses during a performance test.XCTMemoryMetricto record the physical memory that a performance test uses.XCTOSSignpostMetricto record the time that a performance test spends executing a signposted region of code.XCTStorageMetricto record the amount of data that a performance test logically writes to storage.XCTApplicationLaunchMetricto record the application launch duration for a performance test.MonotonicClockMetricto record the time(in nanoseconds) that elapses during a performance test, implemented as a customXCTMetric.scrollDecelerationMetricto record scroll deceleration animations.scrollDraggingMetricto record scroll-dragging animations.navigationTransitionMetricto record the duration of navigation transitions between views.wallClockTimeto record the time in seconds to execute a block of code.- And, all private metrics of
XCTPerformanceMetricsystem.
- Xcode 12.0 Beta 6, Build version 12A8189n.
- Swift 5.3 and later.
- iOS 13 and later.
XCMetrics uses InterposeKit for adding runtime hooks(i.e. swizzling).
XCMetrics welcomes contributions in the form of GitHub issues and pull-requests:
- For PRs, please add the purpose and summary of your changes in the PR description.
- For issues, please add the steps to reproduce and tools/OS version.
- Make sure you test your contributions.
- Ideas and suggestions are very welcome!
By submitting a pull request, you represent that you have the right to license your contribution to Soaurabh Kakkar and the community, and agree by submitting the patch that your contributions are licensed under the XCMetrics project license.
XCMetrics is licensed under the MIT License
https://developer.apple.com/documentation/os/logging/recording_performance_data
https://developer.apple.com/documentation/xctest/performance_tests
https://developer.apple.com/documentation/xctest/xctestcase
https://indiestack.com/2018/02/xcodes-secret-performance-tests
https://developer.apple.com/videos/play/wwdc2018/405
https://developer.apple.com/videos/play/wwdc2019/417
https://developer.apple.com/videos/play/wwdc2020/10077
Building an end to end performance tests CI pipeline? Give XCTool a try!