Skip to content

Instantly share code, notes, and snippets.

@sbodenstein
Created May 25, 2020 15:28
Show Gist options
  • Save sbodenstein/1205995844d236e2f40fd58cdc94d22e to your computer and use it in GitHub Desktop.
Save sbodenstein/1205995844d236e2f40fd58cdc94d22e to your computer and use it in GitHub Desktop.
OpenSpiel Random Game Benchmark Swift
// Build with with `-O` and `Whole Module optimization` flags
import Dispatch
import Foundation
import OpenSpiel
func playRandomGame<T: GameProtocol>(_ game: T) {
var state = game.initialState
while !state.isTerminal {
state.apply(state.legalActions.randomElement()!)
}
}
let game = TicTacToe()
let n: Int = 1000
let start = DispatchTime.now()
for _ in 1...n {
playRandomGame(game)
}
let timeDiff = Double(DispatchTime.now().uptimeNanoseconds - start.uptimeNanoseconds) / Double(n)
print("Mean Random Game Time (μs): \(timeDiff / 1e3)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment