Skip to content

Instantly share code, notes, and snippets.

@jamesonthecrow
Last active February 28, 2018 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesonthecrow/a6454c490efbc7fc177fd8d5353c36fe to your computer and use it in GitHub Desktop.
Save jamesonthecrow/a6454c490efbc7fc177fd8d5353c36fe to your computer and use it in GitHub Desktop.
Benchmarking neural networks in Swift.
struct Debug {
struct Timer {
let start = DispatchTime.now().uptimeNanoseconds
func end() -> Double {
let end = DispatchTime.now().uptimeNanoseconds
let diff = Double(end — start) / 1_000_000_000
return diff
}
}
}
func timePredict(model: MLModel, inputFeatureProvider: MLFeatureProvider) -> Double {
let timer = Debug.Timer()
_ = try? model.prediction(from: inputFeatureProvider)
return timer.end()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment