import Benchmark import Foundation import WmapParser let benchmarks: @Sendable () -> Benchmark? = { // Load the wmap files from Documentation directory let fileManager = FileManager.default let currentDirectory = fileManager.currentDirectoryPath let documentationPath = (currentDirectory as NSString).appendingPathComponent("Documentation") let examplePath = (documentationPath as NSString).appendingPathComponent("example.wmap") let hugePath = (documentationPath as NSString).appendingPathComponent("huge.wmap") let exampleSource: String let hugeSource: String do { exampleSource = try String(contentsOfFile: examplePath, encoding: .utf8) } catch { print("Current directory: \(currentDirectory)") print("Failed to load example.wmap from: \(examplePath)") print("Error: \(error)") fatalError("Failed to load example.wmap") } do { hugeSource = try String(contentsOfFile: hugePath, encoding: .utf8) } catch { print("Failed to load huge.wmap from: \(hugePath)") print("Error: \(error)") fatalError("Failed to load huge.wmap") } Benchmark.defaultConfiguration.maxDuration = .seconds(3) Benchmark.defaultConfiguration.maxIterations = 500 Benchmark("parse example") { benchmark in for _ in benchmark.scaledIterations { blackHole(WmapParser.parse(exampleSource)) } } return Benchmark("parse huge") { benchmark in for _ in benchmark.scaledIterations { blackHole(WmapParser.parse(hugeSource)) } } }