{"id":3151,"url":"https://github.com/SwiftStudies/Duration","last_synced_at":"2025-08-06T13:32:49.112Z","repository":{"id":176097475,"uuid":"54101275","full_name":"SwiftStudies/Duration","owner":"SwiftStudies","description":"A simple Swift package for measuring and reporting the time taken for operations","archived":false,"fork":false,"pushed_at":"2020-09-06T12:15:12.000Z","size":35,"stargazers_count":324,"open_issues_count":0,"forks_count":17,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-08-18T16:36:02.629Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/SwiftStudies.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-03-17T08:29:08.000Z","updated_at":"2024-01-05T07:10:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"f07bfec4-b392-4455-bf0d-cac35389a5b4","html_url":"https://github.com/SwiftStudies/Duration","commit_stats":null,"previous_names":["swiftstudies/duration"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftStudies%2FDuration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftStudies%2FDuration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftStudies%2FDuration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftStudies%2FDuration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SwiftStudies","download_url":"https://codeload.github.com/SwiftStudies/Duration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228905519,"owners_count":17989779,"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-01-05T20:16:32.870Z","updated_at":"2024-12-09T14:31:06.461Z","avatar_url":"https://github.com/SwiftStudies.png","language":"Swift","funding_links":[],"categories":["Tools","Libs","WebSocket","Logging [🔝](#readme)"],"sub_categories":["Web View","Logging","Other free courses"],"readme":"[![Build Status](https://travis-ci.org/SwiftStudies/Duration.svg?branch=master)](https://travis-ci.org/SwiftStudies/Duration)\n\n# Duration\nA simple Swift package for measuring and reporting the time taken for operations. It is derived from [a version for Playgrounds](http://www.swift-studies.com/blog/2015/5/21/performance-testing-in-xcode-playgrounds) that I blogged about some time ago, but kept needing to use in various projects. \n\n## License \nDuration is distributed under the Apache 2.0 license\n\n## Usage\n\nDuration supports iOS, OS X, tvOS, and Linux.\n\n## Installation\n\n### Install via the Swift Package Manager\n\nAdd the following to your Package.swift\n```swift\n\t.Package(url: \"https://github.com/SwiftStudies/Duration.git\", majorVersion: 1)\n```\n\n### Simple Measurements\n\nThere are two methods for simple timing measurements. You can insert calls before and after the section of code you wish to measure, for example\n```swift\n\tDuration.startMeasurement(\"Tough Math\")\n\t\n\tyourToughMathStuff()\n\t\n\tDuration.stopMeasurement()\n```\nOr you can use a block\n```swift\n\tDuration.measure(\"Tough Math\"){\n\t\tyourToughMathStuff()\n\t}\n```\nOr even\n```swift\n\tDuration.measure(\"Tough Math\", block: yourToughMathStuff)\n```\nIn all cases (by default) you will get the output (assuming it took 243 milliseconds)\n\u003eTough Math took: 243ms\n\nIf measurements are nested, they will be appropriately indented in the output, for example if `yourToughMath()` made a measurement of part of its code you would see\n\u003e\n\tMeasuring Tough Math:\n\t\tPart 1 took: 100ms\n\t\tPart 2 took: 143ms\n\tTough Math took: 243ms\n\n### Understanding Performance Deviations\n\nIn order to better understand how your code is impacted by other things the system is doing you can get average times and standard deviations for block based measurements by supplying a number of iterations for the block, so\n```swift\n\tDuration.measure(\"Tough Math\", iterations: 10, forBlock:myToughMath)\n```\nWould run the block 10 times, taking and reporting the 10  individual measurements and then the average time taken for the block, together with the standard deviation\n\u003e\n\tMeasuring Tough Math\n\t\tIteration 1 took: 243ms\n\t\tIteration 2 took: 242ms\n\t\t...\n\t\tIteration 10 took: 243ms\n\tTough Math Average: 243ms\n\tTough Math STD Dev.: 1ms\n\n### Stopping Report Generation\n\nBecause you may want to stop reporting of measurements in release builds, you can set the `logStyle` variable in order to control the logging behavior\n```swift\n\tDuration.logStyle = .None\n```\nWill disable measurement logging. In the future I will extend this library to support logging to a data-structure for subsequent analysis, but at this point there are two valid values `.None` and `.Print` \n\nIf you are using Duration within a Package of your own that you are distributing, rather than just over-writing the log style, you can push your desired style, then pop it to restore it to what a consuming package would want. For example\n```swift\n\tpublic func myMethod(){\n\t\t//Because this is a release of your package\n\t\t//don't log measurements\n\t\tpushLogStyle(.None)\n\t\t\n\t\t// Do stuff that is instrumented\n\t\t\n\t\t//Restore the logging style to whatever it was\n\t\t//before\n\t\tpopLogStyle()\n\t}\n```\n# Reporting Issues\nPlease report issues using GitHub's standard system\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSwiftStudies%2FDuration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSwiftStudies%2FDuration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSwiftStudies%2FDuration/lists"}