Latest 0.5
License MIT
Platforms ios 8.0, osx 10.9, tvos 9.0, watchos 2.0

A simple stopwatches use to logging out the elapsed time between 2 timestamp, easily find out execution time of any function, a block of code or async callback.



Add below line to your project Podfile

pod 'Watches'

Then run pod install from Terminal


Drag and drop Watches.swift source file into your project


By default, Watches will automatically print out the debugging log in format

"Elapsed interval for (identifier) is (interval)"

If you want to disable this auto log feature, set

Watches.printElapsedTimeAutomatically = false

Track elapsed time of any async callback (e.g : network request)
call tick to tickoff the time with specific identifier right before calling async task


Then call tock with the corresponding identifier inside async callback closure


For example with Alamofire

Alamofire.request(loadProfileUrl).responseJSON { response in

It will print out the elapsed intervals in default format

Result: Elapsed interval for LoadProfile is 1.20113898515701

Feel free to provide custom format that you desire

Watches.tock("LoadProfile") { debugPrint("Time needed for ($0) is ($1)") }

If you want the elapsed interval for your own purpose, get it from the tock return value

//You can disable auto print feature if you want
Watches.printElapsedTimeAutomatically = false

//Then get the result from tock function
let elapsedTime = Watches.tock("LoadProfile")

Determine the execution time of any block of code.

Watches.create("1 million times loop").tick {
    //Block of code to measure
    for _ in 0...10000000 { }


Result: Elapsed interval for 1 million times loop is 0.214788019657135

If you want custom print format, just need to provide the tock callback closure.

Watches.create("2 million times loop").tick {
    //Block of code to measure
    for _ in 0...20000000 { }

}.tock { debugPrint("Time for finishing ($0) is ($1)")}

Result: Time for finishing 2 million times loop is 0.411646008491516

If you just want to get the result

let executionTime = Watches.create("MyClosure").tick { 
    //Block of code to measure


Result: 3.0011550188064575


Watches is released under the MIT License. See LICENSE file for more detail. Copyright © Vuong Huu Tai

Latest podspec

    "name": "Watches",
    "version": "0.5",
    "summary": "A Simple Stopwatches written in Swift help you easily measure the execution time of function, block of code or async callback.",
    "description": "A Simple swift stopwatches helps you easily logging out the elapsed time between 2 timestamps , find out execution time of function, a block of code or async callback.",
    "homepage": "",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "tvos": "9.0",
        "watchos": "2.0"
    "swift_version": "4.2",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Tai Vuong": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.5"
    "source_files": "Watches/*.swift"

Pin It on Pinterest

Share This