Code Monkey home page Code Monkey logo

benchmark's Introduction

Benchmark

The Benchmark⏲ module provides methods to measure and report the time used to execute Swift code.

License Language Carthage compatible CocoaPods compatible Awesome

Installation

Carthage

// Cartfile
github "WorldDownTown/Benchmark"

CocoaPods

// Podfile
pod 'Benchmark'

Usage

Simple measure

import Benchmark

Benchmark.measure() {
    print(self) // don't have to set weak.
    for _ in 0...10000000 { }
}
// Benchmark: 0.1690970063 sec.

// Benchamrk can be set name.
Benchmark.measure("Measure1") {
    for _ in 0...10000000 { }
}
// Measure1: 0.1690970063 sec.

Multiple measure

import Benchmark

func heavyMethod() {
    let outer = Benchmark(key: "outer")

    let inner = Benchmark(key: "inner")

    // some light processes
    for _ in 0...10 { }

    inner.finish()  // inner: 0.0002210140 sec.

    // some heavy processes
    for _ in 0...10000000 { }

    outer.finish()  // outer: 0.1663100123 sec.
}

Through another Class (or Struct or file ...)

import Benchmark

class Foo {
    func execute() {
        Benchmark.start()
    }
}

class Bar {
    func execute() {
        Benchmark.finish()
    }
}

Foo().execute()

Bar().execute()  // Benchmark: 0.0001509786 sec.

Using operator

import Benchmark

// same as Benchmark.measure {}
{
    for _ in 0...10000000 { }
}
// Benchmark: 0.1653281017 sec.

Contributing

Contributions are more than welcome! If you have an improvement or a feature you wish to have added to Benchmark, then please don't hesitate to send a pull request!

Author

WorldDownTown @ gmail.com

License

Benchmark is available under the MIT license. See the LICENSE file for more info.

benchmark's People

Contributors

worlddowntown avatar

Watchers

 avatar  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.