Swift.org Blog Joakim Hassila Mar 20, 2024

Swift Performance Benchmarks

Article Summary

Joakim Hassila from Ordo One built a performance benchmarking tool that major Swift projects like Foundation, SwiftNIO, and SwiftPM are now using. If you're shipping Swift code without performance tests, you're flying blind.

The Benchmark package is an open-source SwiftPM plugin that brings the same rigor to performance testing that unit tests bring to functionality. Built by a team running high-performance trading systems, it tracks 20+ metrics from CPU time to memory leaks to syscalls, and integrates directly into CI pipelines.

Key Takeaways

Critical Insight

Swift now has a comprehensive benchmarking framework that makes performance testing as routine as unit testing, with CI integration and support for both macOS and Linux.

The article reveals how trading systems measure performance in microseconds and why the existing Swift ecosystem couldn't meet those needs.

About This Article

Problem

Swift developers had to piece together performance testing using separate tools like Instruments and DTrace because the language lacked a unified benchmarking framework. There was no standard way to measure multi-platform metrics or integrate performance checks into CI pipelines.

Solution

Ordo One built the Benchmark package as a SwiftPM command plugin that handles performance testing automatically. It tracks over 20 metrics including CPU time, memory allocation, syscalls, and ARC retain/release counts on both macOS and Linux.

Impact

Foundation, SwiftPM, SwiftNIO, and Google Flatbuffers all adopted the package. Teams now run automated regression checks on pull requests and monitor performance consistently within their CI pipelines.