Swiftpack.co - google/swift-benchmark as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
A swift library to benchmark code snippets.
.package(url: "https://github.com/google/swift-benchmark.git", from: "0.1.1")


A Swift library for benchmarking code snippets, similar to google/benchmark.


import Benchmark

benchmark("add string reserved capacity") {
    var x: String = ""
    for _ in 1...1000 {
        x += "hi"


At runtime, you can filter which benchmarks to run by using the --filter command line flag. For more details on what options are available, pass either the -h or --help command line flags.


$ swift run -c release BenchmarkMinimalExample --help
USAGE: benchmark-command [--allow-debug-build] [--filter <filter>] [--filter-not <filter-not>] [--iterations <iterations>] [--warmup-iterations <warmup-iterations>] [--min-time <min-time>] [--max-iterations <max-iterations>] [--time-unit <time-unit>] [--inverse-time-unit <inverse-time-unit>] [--columns <columns>] [--format <format>] [--quiet]

  --allow-debug-build     Overrides check to verify optimized build.
  --filter <filter>       Run only benchmarks whose names match the regular expression.
  --filter-not <filter-not>
                          Exclude benchmarks whose names match the regular expression.
  --iterations <iterations>
                          Number of iterations to run.
  --warmup-iterations <warmup-iterations>
                          Number of warm-up iterations to run.
  --min-time <min-time>   Minimal time to run when automatically detecting number iterations.
  --max-iterations <max-iterations>
                          Maximum number of iterations to run when automatically detecting number iterations.
  --time-unit <time-unit> Time unit used to report the timing results.
  --inverse-time-unit <inverse-time-unit>
                          Inverse time unit used to report throughput results.
  --columns <columns>     Comma-separated list of column names to show.
  --format <format>       Output format (valid values are: json, csv, console, none).
  --quiet                 Only print final benchmark results.
  -h, --help              Show help information.

$ swift run -c release BenchmarkMinimalExample
running add string no capacity... done! (1832.52 ms)
running add string reserved capacity... done! (1813.96 ms)

name                         time     std        iterations
add string no capacity       37435 ns ±   6.22 %      37196
add string reserved capacity 37022 ns ±   1.75 %      37749

For more examples, see Sources/BenchmarkMinimalExample and Sources/BenchmarkSuiteExample.


Add this library as a SwiftPM dependency:

dependencies: [
    .package(url: "https://github.com/google/swift-benchmark", from: "0.1.0"),


The project is in an early stage and offers only a basic set of benchmarking utilities. Feel free to file issues and feature requests to help us prioritize what to do next.


Please see LICENSE for details.


Please see CONTRIBUTING.md for details.


Stars: 708
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

1 week ago

Minor update for supporting swift-benchmark on Windows targets on 5.4 or newer Swift releases.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics