Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Scripts/measure-launch.swift3// Description: Measures the cold launch of the development variant: time from process start to its first window on screen (polled every 5 ms through the window server; nothing is captured). The app is stopped after each run.4// Usage: swift Scripts/measure-launch.swift [runs] (only ever starts and stops "SP Drive Dev")5import CoreGraphics6import Foundation78let bin = NSString(string: "~/Library/Developer/SPDrive/DerivedData/Build/Products/Debug/SP Drive Dev.app/Contents/MacOS/SP Drive Dev").expandingTildeInPath9let runs = CommandLine.arguments.count > 1 ? Int(CommandLine.arguments[1]) ?? 3 : 310var results: [Double] = []11for _ in 0..<runs {12 let p = Process(); p.executableURL = URL(fileURLWithPath: bin); p.arguments = ["-ApplePersistenceIgnoreState", "YES"]13 p.standardOutput = FileHandle.nullDevice; p.standardError = FileHandle.nullDevice14 let start = DispatchTime.now()15 try p.run()16 var shown: Double?17 while shown == nil, DispatchTime.now().uptimeNanoseconds - start.uptimeNanoseconds < 15_000_000_000 {18 let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] ?? []19 if list.contains(where: { ($0["kCGWindowOwnerPID"] as? Int32) == p.processIdentifier && ($0["kCGWindowLayer"] as? Int) == 0 && (($0["kCGWindowBounds"] as? [String: Any])?["Width"] as? Double ?? 0) > 300 }) {20 shown = Double(DispatchTime.now().uptimeNanoseconds - start.uptimeNanoseconds) / 1e621 } else { usleep(5000) }22 }23 p.terminate(); p.waitUntilExit()24 if let shown { results.append(shown); print(String(format: "first window after %.0f ms", shown)) } else { print("no window within 15 s") }25 sleep(1)26}27if !results.isEmpty { print(String(format: "median %.0f ms over %d runs", results.sorted()[results.count / 2], results.count)) }28