Giter Club home page Giter Club logo

duration's Introduction

Build Status

Duration

A simple Swift package for measuring and reporting the time taken for operations

License

Duration is distributed under the Apache 2.0 license

Usage

Simple Measurements

There are two methods for simple timing measurements. You can insert calls before and after the section of code you wish to measure, for example

Duration.startMeasurement("Tough Math")

yourToughMathStuff()

Duration.stopMeasurement()

Or you can use a block

Duration.measure("Tough Math"){
	yourToughMathStuff()
}

Or even

Duration.measure("Tough Math", block: yourToughMathStuff)

In all cases (by default) you will get the output (assuming it took 243 milliseconds)

Tough Math took: 243ms

If 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

Measuring Tough Math:
	Part 1 took: 100ms
	Part 2 took: 143ms
Tough Math took: 243ms

Understanding Performance Deviations

In 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

Duration.measure("Tough Math", iterations: 10, forBlock:myToughMath)

Would 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

Measuring Tough Math
	Iteration 1 took: 243ms
	Iteration 2 took: 242ms
	...
	Iteration 10 took: 243ms
Tough Math Average: 243ms
Tough Math STD Dev.: 1ms

Stopping Report Generation

Because you may want to stop reporting of measurements in release builds, you can set the logStyle variable in order to control the logging behavior

Duration.logStyle = .None

Will 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

If 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

public func myMethod(){
	//Because this is a release of your package
	//don't log measurements
	pushLogStyle(.None)
	
	// Do stuff that is instrumented
	
	//Restore the logging style to whatever it was
	//before
	popLogStyle()
}

Reporting Issues

Please report issues using GitHub's standard system

duration's People

Contributors

swiftstudies avatar

Watchers

James Cloos avatar Carabineiro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.