Skip to content

Instantly share code, notes, and snippets.

@Anemll
Last active June 10, 2025 00:42
Show Gist options
  • Save Anemll/fdd00aa2d89e51418aad5f89e462d489 to your computer and use it in GitHub Desktop.
Save Anemll/fdd00aa2d89e51418aad5f89e462d489 to your computer and use it in GitHub Desktop.
Test Apple Foundation Model t/s
import FoundationModels
import Playgrounds
import Foundation
let session = LanguageModelSession()
let start = Date()
let response = try await session.respond(to: "What is Apple Neural Engine and how to use it?")
let responseText = response.content // Replace 'value' with the actual property name from LanguageModelSession.Response<String> that holds the string payload.
print(responseText)
let end = Date()
let elapsed = end.timeIntervalSince(start)
let charCount = responseText.count
let estimatedTokensMin = charCount / 4
let estimatedTokensMax = charCount / 3
let tokensPerSecondMin = elapsed > 0 ? Double(estimatedTokensMin) / elapsed : 0
let tokensPerSecondMax = elapsed > 0 ? Double(estimatedTokensMax) / elapsed : 0
print("Characters: \(charCount)")
print("Estimated tokens: \(estimatedTokensMin) - \(estimatedTokensMax)")
print(String(format: "Tokens per second: %.2f - %.2f", tokensPerSecondMin, tokensPerSecondMax))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment