Skip to content

Instantly share code, notes, and snippets.

@bre7
Last active August 30, 2017 02:22
Show Gist options
  • Select an option

  • Save bre7/e087151aa32baf80c2ea22fadcdb2d5c to your computer and use it in GitHub Desktop.

Select an option

Save bre7/e087151aa32baf80c2ea22fadcdb2d5c to your computer and use it in GitHub Desktop.

Simple benchmarking in Swift

Credit goes to NSHipster: http://nshipster.com/benchmarking/

  1. Add the following to the bridging header:
#include <stdint.h>
extern uint64_t dispatch_benchmark(size_t count, void (^block)(void));
  1. Benchmark any code using:
let time = dispatch_benchmark(10) {
    // BENCHMARK ME!
}
NSLog("Avg. Runtime: %llu ns", time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment