{"id":15036398,"url":"https://github.com/apple/swift-collections-benchmark","last_synced_at":"2025-05-15T21:04:47.497Z","repository":{"id":43901243,"uuid":"349577257","full_name":"apple/swift-collections-benchmark","owner":"apple","description":"A benchmarking tool for Swift Collection algorithms","archived":false,"fork":false,"pushed_at":"2025-03-10T21:49:43.000Z","size":7616,"stargazers_count":355,"open_issues_count":7,"forks_count":22,"subscribers_count":120,"default_branch":"main","last_synced_at":"2025-05-03T20:02:46.465Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apple.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-19T23:09:59.000Z","updated_at":"2025-05-02T19:15:45.000Z","dependencies_parsed_at":"2025-03-29T02:00:24.335Z","dependency_job_id":"a229051a-818c-45c1-afeb-09aff5003bde","html_url":"https://github.com/apple/swift-collections-benchmark","commit_stats":{"total_commits":11,"total_committers":6,"mean_commits":"1.8333333333333333","dds":0.4545454545454546,"last_synced_commit":"e8b88af0d678eacd65da84e99ccc1f0f402e9a97"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apple%2Fswift-collections-benchmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apple%2Fswift-collections-benchmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apple%2Fswift-collections-benchmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apple%2Fswift-collections-benchmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apple","download_url":"https://codeload.github.com/apple/swift-collections-benchmark/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254422754,"owners_count":22068678,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T20:31:02.309Z","updated_at":"2025-05-15T21:04:47.473Z","avatar_url":"https://github.com/apple.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swift Collections Benchmark\n\nThis package lets you collect and easily visualize performance data about data structure implementations and collection algorithms. It was created to help develop the [Swift Collections] package, but it's useful for so much more!\n\n[Swift Collections]: https://github.com/apple/swift-collections\n\nThis project primarily concentrates on benchmarking Swift code, but it can also be used to run benchmarks (and, especially, to analyze benchmark results) in other languages, too.\n\n## Example\n\nHere is a short benchmark, measuring the performance of `Array.sorted()` and `Set.contains(_:)`:\n\n``` swift\nimport CollectionsBenchmark\n\nvar benchmark = Benchmark(title: \"Demo Benchmark\")\n\nbenchmark.addSimple(\n  title: \"Array\u003cInt\u003e sorted\",\n  input: [Int].self\n) { input in\n  blackHole(input.sorted())\n}\n\nbenchmark.add(\n  title: \"Set\u003cInt\u003e contains\",\n  input: ([Int], [Int]).self\n) { input, lookups in\n  let set = Set(input)\n  return { timer in\n    for value in lookups {\n      precondition(set.contains(value))\n    }\n  }\n}\n\nbenchmark.main()\n```\n\nHere is how you run it:\n\n``` shellsession\n$ swift run -c release benchmark run results --cycles 5\nRunning 2 tasks on 76 sizes from 1 to 1M:\n  Array\u003cInt\u003e sorted\n  Set\u003cInt\u003e contains\nOutput file: /Users/klorentey/Projects/swift-collections-benchmark-demo/Demo/results\nAppending to existing data (if any) for these tasks/sizes.\n\nCollecting data:\n  1.2.4...8...16...32...64...128...256...512...1k...2k...4k...8k...16k...32k...64k...128k...256k...512k...1M -- 5.31s\n  1.2.4...8...16...32...64...128...256...512...1k...2k...4k...8k...16k...32k...64k...128k...256k...512k...1M -- 5.35s\n  1.2.4...8...16...32...64...128...256...512...1k...2k...4k...8k...16k...32k...64k...128k...256k...512k...1M -- 5.29s\n  1.2.4...8...16...32...64...128...256...512...1k...2k...4k...8k...16k...32k...64k...128k...256k...512k...1M -- 5.3s\n  1.2.4...8...16...32...64...128...256...512...1k...2k...4k...8k...16k...32k...64k...128k...256k...512k...1M -- 5.34s\nFinished in 26.6s\n$ swift run -c release benchmark render results chart.png\n$ open chart.png\n```\n\nAnd this is what you get:\n\n![chart.png](Documentation/Assets/demo-chart.png)\n\nToday I learned that sorting 20 integers in an `Array` takes about as much time as looking at all items in a 20-member `Set`. Fascinating! 🤓\n\n## Documentation\n\nFor a tour of the features provided by this library, please be sure check out our [Getting Started Guide][guide]!\n\n[guide]: Documentation/01%20Getting%20Started.md\n\n## Project Status\n\nSwift Collections Benchmark is intended primarily as a developer tool, rather than something that would be used in production apps.\n\nIt exposes a source-level API and a command line interface, neither of which are technically stable yet. After an initial period of experimentation, we expect to stabilize both interfaces. Until then, new releases may sometimes come with changes that might break existing benchmark definitions, or that may change the command line interface in ways that could break existing scripts. We'll try our best to keep this to a minimum, though (or mitigate with a multi-release deprecation period), even during this chaotic initial period.\n\n## Adding Swift Collections Benchmark as a Dependency\n\nTo use this package in a SwiftPM project, add the following line to the dependencies in your `Package.swift` file:\n\n```swift\n.package(url: \"https://github.com/apple/swift-collections-benchmark\", from: \"0.0.1\"),\n```\n\nIn the typical case, you'll want to set up a standalone executable target that is dedicated to benchmarking:\n\n```swift\n// swift-tools-version:5.3\nimport PackageDescription\n\nlet package = Package(\n  name: \"MyPackage\",\n  products: [\n    .executable(name: \"my-benchmark\", targets: [\"MyBenchmark\"]),\n  ],\n  dependencies: [\n    .package(url: \"https://github.com/apple/swift-collections-benchmark\", from: \"0.0.1\"),\n    // ... other dependencies ...\n  ],\n  targets: [\n    // ... other targets ...\n    .target(\n      name: \"MyBenchmark\",\n      dependencies: [\n        .product(name: \"CollectionsBenchmark\", package: \"swift-collections-benchmark\"),\n      ]),\n  ]\n)\n```\n\n## Contributing to Swift Collections Benchmark\n\n### Asking questions\n\nWe can use the [Swift Collections Forum][forum] to ask and answer questions on how to use or work on this package. It's also a great place to discuss its evolution.\n\n[forum]: https://forums.swift.org/c/related-projects/collections\n\n### Reporting a bug\n\nIf you find something that looks like a bug, please open a [Bug Report][bugreport]! Fill out as many details as you can.\n\n[bugreport]: https://github.com/apple/swift-collections-benchmark/issues/new?assignees=\u0026labels=bug\u0026template=BUG_REPORT.md\n\n### Fixing a bug or making a small improvement\n\n1. [Submit a PR][PR] with your change. If there is an [existing issue][issues] for the bug you're fixing, please include a reference to it.\n2. Make sure to add test coverage for whatever changes you are making (if possible).\n\n[PR]: https://github.com/apple/swift-collections-benchmark/compare\n[issues]: https://github.com/apple/swift-collections-benchmark/issues\n\n(Note: The package doesn't currently come with many tests, reflecting its origins as a supporting project -- we strive to improve that!)\n\n### Proposing a small enhancement\n\n1. Raise a [Feature Request][enhancement]. Discuss why it would be important to implement it.\n2. Submit a PR with your implementation, participate in the review discussion.\n3. When there is a consensus that the feature is desirable, and the implementation works well, it will be merged. \n4. Rejoice!\n\n[enhancement]: https://github.com/apple/swift-collections-benchmark/issues/new?assignees=\u0026labels=enhancement\u0026template=FEATURE_REQUEST.md\n\n### Proposing a larger feature\n\n1. Raise a [Feature Request][enhancement], or start a topic on the [forum]. Discuss why it would be important to implement it, and potential implementation strategies.\n2. Submit a PR with your implementation, and participate in the review discussion. Sometimes we may need to go through several revisions! This is fine -- it makes the end result that much better.\n3. When there is a consensus that the feature is desirable, and the implementation works well, it will be merged. \n4. Celebrate! \n\n### Licensing\n\nBy submitting a pull request, you represent that you have the right to license your contribution to Apple and the community, and agree by submitting the patch that your contributions are licensed under the [Swift License](https://swift.org/LICENSE.txt), a copy of which is [provided in this repository](LICENSE.txt).\n\n### Code of Conduct\n\nLike all Swift.org projects, we would like the Swift Collections Benchmark project to foster a diverse and friendly community. We expect contributors to adhere to the [Swift.org Code of Conduct](https://swift.org/code-of-conduct/). A copy of this document is [available in this repository][coc].\n\n[coc]: CODE_OF_CONDUCT.md\n\n### Contacting the maintainers\n\nThe current code owner of this package is Karoy Lorentey ([@lorentey](https://github.com/lorentey)). You can contact him [on the Swift forums](https://forums.swift.org/u/lorentey/summary), or by writing an email to klorentey at apple dot com. (Please keep it related to this project.)\n\nIn case of moderation issues, you can also directly contact a member of the [Swift Core Team](https://swift.org/community/#community-structure).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapple%2Fswift-collections-benchmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapple%2Fswift-collections-benchmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapple%2Fswift-collections-benchmark/lists"}