Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : Sources/qyvora-bench/main.swift8// Module : Qyvora Bench9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0412// Last Modified : 2026-12-0413//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import Foundation42import QyvoraBenchmarks4344// qyvora-bench: command-line front end of the QYVORA benchmark suite.4546let usage = """47 Usage: qyvora-bench [--quick|--full] [--filter <substring>] [--json <path>] [--markdown <path>] [--list] [--sizes]4849 --quick about 0.15 s per benchmark (default)50 --full about 1 s per benchmark51 --filter <text> keep the benchmarks whose identifier, name or family contains <text>52 --json <path> write the report as JSON53 --markdown <path> write the report as Markdown54 --list print the benchmark identifiers and exit55 --sizes print the key / signature / ciphertext size table and exit56 --help this text5758 """5960func fail(_ message: String) -> Never {61 FileHandle.standardError.write(Data("qyvora-bench: \(message)\n\(usage)".utf8))62 exit(2)63}6465var configuration = BenchmarkConfiguration.quick66var filter: String?67var jsonPath: String?68var markdownPath: String?69var listOnly = false70var sizesOnly = false7172var arguments = Array(CommandLine.arguments.dropFirst())73while !arguments.isEmpty {74 let argument = arguments.removeFirst()75 func value() -> String {76 guard !arguments.isEmpty else { fail("missing value after \(argument)") }77 return arguments.removeFirst()78 }79 switch argument {80 case "--quick": configuration = .quick81 case "--full": configuration = .full82 case "--filter": filter = value()83 case "--json": jsonPath = value()84 case "--markdown": markdownPath = value()85 case "--list": listOnly = true86 case "--sizes": sizesOnly = true87 case "--help", "-h":88 print(usage)89 exit(0)90 default: fail("unknown argument \(argument)")91 }92}9394if sizesOnly {95 print(MarkdownRenderer.sizeTable(), terminator: "")96 exit(0)97}9899let benchmarks = BenchmarkCatalogue.all.filtered(by: filter)100101if listOnly {102 for b in benchmarks {103 print("\(b.id.padding(toLength: 44, withPad: " ", startingAt: 0)) \(b.family.rawValue.padding(toLength: 10, withPad: " ", startingAt: 0)) \(b.displayName)")104 }105 exit(0)106}107108guard !benchmarks.isEmpty else { fail("no benchmark matches \"\(filter ?? "")\"") }109110let environment = BenchmarkEnvironment.current()111print("QYVORA benchmarks — \(configuration.name) mode, \(benchmarks.count) benchmarks")112print(environment.summary)113if environment.buildConfiguration == "debug" {114 print("warning: debug build; numbers are not representative (use swift build -c release)")115}116print("")117118let runner = BenchmarkRunner(configuration: configuration)119let report = try await runner.run(benchmarks) { progress in120 switch progress {121 case .started:122 break123 case let .finished(result, index, total):124 let s = result.statistics125 let position = "[\(index + 1)/\(total)]".padding(toLength: 10, withPad: " ", startingAt: 0)126 let name = result.displayName.padding(toLength: 46, withPad: " ", startingAt: 0)127 let headline = result.headline.padding(toLength: 24, withPad: " ", startingAt: 0)128 print("\(position)\(name)\(headline)median \(BenchmarkFormat.duration(s.median)) sd \(BenchmarkFormat.duration(s.standardDeviation)) n=\(result.iterations) cpu \(BenchmarkFormat.number(result.cpuUtilization))×")129 fflush(stdout)130 case let .failed(failure, index, total):131 print("[\(index + 1)/\(total)] \(failure.displayName) FAILED: \(failure.message)")132 fflush(stdout)133 }134}135136print("")137print("wall time \(BenchmarkFormat.duration(report.wallTime)), CPU time \(BenchmarkFormat.duration(report.cpuTime)), thermal state \(report.thermalTransition)")138139if let jsonPath {140 try report.jsonData().write(to: URL(fileURLWithPath: jsonPath))141 print("JSON written to \(jsonPath)")142}143if let markdownPath {144 try Data(report.markdown().utf8).write(to: URL(fileURLWithPath: markdownPath))145 print("Markdown written to \(markdownPath)")146}147148exit(report.failures.isEmpty ? 0 : 1)149