Skip to content

Instantly share code, notes, and snippets.

Forked from akirasosa/mlSpeedTests.swift
Created May 19, 2020 09:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save skeeet/191944c46695aada2f9c69e8131e40d4 to your computer and use it in GitHub Desktop.
Benchmark Core ML model in iOS.
import CoreML
import XCTest
@testable import mlsample
class mlsampleTests: XCTestCase {
override func setUp() {
override func tearDown() {
func testSpeed() {
guard let input_data = try? MLMultiArray(shape:[3, 160, 160], dataType:MLMultiArrayDataType.double) else {
fatalError("Unexpected runtime error. MLMultiArray")
let model = mobile_unet_160_100_100()
// It's for excluding 1st measurement.
do {
try model.prediction(data: input_data)
} catch {
self.measure() {
try! model.prediction(data: input_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment