SPB Git

Repository Public

PerfUITests.swift 4.8 KB 86 lines swift

1//2//  SP Chat iOS3//  File: SPChat-iOS/UITests/PerfUITests.swift4//  Description: Performance measurements (Scripts/perf.sh, local stand-in backend with a 450-model catalogue and a5//               200-message conversation): cold launch, opening and scrolling a long transcript, memory with the6//               catalogue loaded. Simulator figures — indicative only.7//8//  Author: Simon-Pierre Boucher9//  Contact: contact@spboucher.ai10//1112import XCTest1314final class PerfUITests: XCTestCase {15    private var enabled: Bool { ProcessInfo.processInfo.environment["SPCHAT_PERF"] == "1" }16    private var isPad: Bool { UIDevice.current.userInterfaceIdiom == .pad }1718    private func app(link: String? = nil) -> XCUIApplication {19        let app = XCUIApplication()20        app.launchEnvironment["SPCHAT_UI_TESTS"] = "1"21        app.launchEnvironment["SPCHAT_BASE_URL"] = ProcessInfo.processInfo.environment["SPCHAT_BASE_URL"] ?? "http://localhost:8599"22        app.launchEnvironment["SPCHAT_DEBUG_SESSION"] = String(repeating: "p", count: 43)23        app.launchEnvironment["SPCHAT_UI_MODEL"] = "perf-direct-0"24        if let link { app.launchEnvironment["SPCHAT_UI_LINK"] = link }25        app.launchArguments += ["-AppleLanguages", "(fr)", "-AppleLocale", "fr_CA"]26        return app27    }2829    func testColdLaunch() throws {30        guard enabled else { throw XCTSkip("mesures de performance : Scripts/perf.sh") }31        // time until the composer can be used (catalogue of 450 models requested and decoded in the background)32        var samples: [Double] = []33        for _ in 0..<5 {34            let a = app(); let t0 = Date(); a.launch()35            XCTAssertTrue(a.textFields["composer.field"].waitForExistence(timeout: 20))36            samples.append(Date().timeIntervalSince(t0)); a.terminate()37        }38        print("PERF launch-to-composer s: \(samples.map { String(format: "%.2f", $0) }.joined(separator: " ")) median \(String(format: "%.2f", samples.sorted()[2]))")39    }4041    func testOpenAndScrollA200MessageTranscript() throws {42        guard enabled else { throw XCTSkip("mesures de performance : Scripts/perf.sh") }43        let a = app(); a.launch()44        XCTAssertTrue(a.textFields["composer.field"].waitForExistence(timeout: 20))45        if !isPad { a.navigationBars.buttons.element(boundBy: 0).tap() }46        let row = a.staticTexts["Transcription de 200 messages"]47        XCTAssertTrue(row.waitForExistence(timeout: 10))48        var open: [Double] = []49        for i in 0..<3 {50            let t0 = Date(); row.tap()51            // the last answer of the thread (« Point 100 ») is on screen: the transcript is open at its end52            XCTAssertTrue(a.staticTexts["Point 100"].waitForExistence(timeout: 20))53            open.append(Date().timeIntervalSince(t0))54            if i < 2 { if isPad { a.buttons["list.new"].tap() } else { a.navigationBars.buttons.element(boundBy: 0).tap() }; _ = row.waitForExistence(timeout: 5) }55        }56        print("PERF open-200-messages s (first = network + decode, next = cached session): \(open.map { String(format: "%.2f", $0) }.joined(separator: " "))")57        // eight fast flicks through the transcript (four up the thread, four back): wall time per flick, gesture58        // synthesis and settling included — a regression indicator, not a frame-rate measurement59        let scroll = a.scrollViews.firstMatch60        var flicks: [Double] = []61        for i in 0..<8 { let t0 = Date(); if i < 4 { scroll.swipeDown(velocity: .fast) } else { scroll.swipeUp(velocity: .fast) }; flicks.append(Date().timeIntervalSince(t0)) }62        XCTAssertTrue(a.textFields["composer.field"].exists)63        print("PERF flick s: \(flicks.map { String(format: "%.2f", $0) }.joined(separator: " ")) mean \(String(format: "%.2f", flicks.reduce(0, +) / 8))")64    }6566    func testMemoryWithTheWholeCatalogue() throws {67        guard enabled else { throw XCTSkip("mesures de performance : Scripts/perf.sh") }68        let a = app(); a.launch()69        XCTAssertTrue(a.textFields["composer.field"].waitForExistence(timeout: 20))70        // open the model sheet, scroll the 450-model list, search, close — three times; the script reads the71        // resident memory of the process before and after (Scripts/perf.sh)72        print("PERF memory-checkpoint before-catalogue-browsing")73        Thread.sleep(forTimeInterval: 3)74        for _ in 0..<3 {75            a.buttons["chat.modelButton"].tap()76            XCTAssertTrue(a.navigationBars["Modèle"].waitForExistence(timeout: 10))77            let list = a.collectionViews.firstMatch78            for _ in 0..<5 { list.swipeUp(velocity: .fast) }79            a.navigationBars["Modèle"].buttons["models.done"].tap()80            XCTAssertTrue(a.textFields["composer.field"].waitForExistence(timeout: 10))81        }82        print("PERF memory-checkpoint after-catalogue-browsing")83        Thread.sleep(forTimeInterval: 6)84    }85}86
Files main
Menu

Theme