Repository Public License
1// ORIX Convert — Packages/EngineDocuments/Tests/EngineDocumentsTests/PerformanceTests.swift2// Description: Measures real conversion times on this machine (LibreOffice start-up, Pandoc, WebKit, a 50-page DOCX)3// and writes them to a report file quoted by docs/compatibility/engines/documents.md.4// Author: Simon-Pierre Boucher — contact@spboucher.ai5import Testing6import Foundation7import PDFKit8@testable import EngineDocuments9import ConvertCore1011@Suite("Performance", .serialized)12struct PerformanceTests {13 @Test func measure() async throws {14 let fx = try await FixtureStore.shared.get()15 let dir = try Fixtures.newDirectory("perf")16 var lines: [String] = []17 func time(_ label: String, _ body: () async throws -> String) async throws {18 let started = Date()19 let note = try await body()20 lines.append(String(format: "%@: %.2f s%@", label, Date().timeIntervalSince(started), note.isEmpty ? "" : " (\(note))"))21 }22 // LibreOffice: every conversion starts a new process with a new profile.23 for i in 1...5 {24 try await time("LibreOffice DOCX→PDF, 1 page, run \(i)") {25 _ = try await LibreOffice.convert(fx.documents[.docx]!, filter: "pdf:writer_pdf_Export", scratch: dir); return ""26 }27 }28 try await time("LibreOffice DOCX→ODT") { _ = try await convert(fx.documents[.docx]!, .docx, .odt); return "engine call incl. reading source and output" }29 try await time("LibreOffice DOC→DOCX") { _ = try await convert(fx.documents[.doc]!, .doc, .docx); return "" }30 try await time("LibreOffice PPTX→PDF, 3 slides") { _ = try await convert(fx.deck[.pptx]!, .pptx, .pdf); return "" }31 try await time("PPTX→PNG, 3 slides at 150 dpi") { let r = try await convert(fx.deck[.pptx]!, .pptx, .png); return "\(r.output.facts["width"] ?? "?") × \(r.output.facts["height"] ?? "?") px each" }32 try await time("PPTX→Markdown text (package XML only)") { _ = try await convert(fx.deck[.pptx]!, .pptx, .markdown); return "" }33 // Pandoc.34 try await time("Pandoc Markdown→DOCX") { _ = try await convert(fx.documents[.markdown]!, .markdown, .docx); return "" }35 try await time("Pandoc Markdown→HTML") { _ = try await convert(fx.documents[.markdown]!, .markdown, .html); return "" }36 try await time("Pandoc DOCX→Markdown") { _ = try await convert(fx.documents[.docx]!, .docx, .markdown); return "" }37 try await time("Pandoc DOCX→EPUB") { _ = try await convert(fx.documents[.docx]!, .docx, .epub); return "" }38 try await time("Pandoc EPUB→HTML") { _ = try await convert(fx.documents[.epub]!, .epub, .html); return "" }39 try await time("LibreOffice + Pandoc DOC→Markdown") { _ = try await convert(fx.documents[.doc]!, .doc, .markdown); return "two steps" }40 // WebKit.41 try await time("Pandoc + WebKit Markdown→PDF, 1 page") { _ = try await convert(fx.documents[.markdown]!, .markdown, .pdf); return "" }42 try await time("WebKit HTML→PDF, 1 page") { _ = try await convert(fx.documents[.html]!, .html, .pdf); return "" }43 // Apple text system.44 try await time("Apple text system RTF→DOCX") { _ = try await convert(fx.documents[.rtf]!, .rtf, .docx, options: ["engine": .string("apple")]); return "in process" }45 // A long document: ~50 pages.46 var long = "---\ntitle: Fifty Pages\nauthor: Benchmark\n---\n\n"47 let sentence = "The quick brown fox jumps over the lazy dog while the conversion engine measures how long a realistic paragraph of body text takes to lay out. "48 for chapter in 1...20 {49 long += "# Chapter \(chapter)\n\n"50 for p in 1...14 { long += String(repeating: sentence, count: 4) + "Paragraph \(chapter).\(p).\n\n" }51 long += "| Column A | Column B | Column C |\n|---|---|---|\n| \(chapter) | value | more |\n| \(chapter + 1) | value | more |\n\n"52 }53 let md = dir.appendingPathComponent("fifty.md")54 try Data(long.utf8).write(to: md)55 let docx = dir.appendingPathComponent("fifty.docx")56 try await time("Pandoc Markdown→DOCX, long document") {57 _ = try await Pandoc.run(["-f", "markdown", "-t", "docx", "-o", docx.path, md.path], scratch: dir)58 let size = (try? docx.resourceValues(forKeys: [.fileSizeKey]).fileSize) ?? 059 return "\(long.split(separator: " ").count) words, \(size / 1024) KiB DOCX"60 }61 try await time("LibreOffice DOCX→PDF, long document") {62 let r = try await convert(docx, .docx, .pdf)63 #expect(r.failedChecks.isEmpty, "\(r.failedChecks)")64 let pages = PDFDocument(url: r.file)?.pageCount ?? 065 #expect((45...56).contains(pages), "about fifty pages: \(pages)")66 return "\(pages) pages"67 }68 try await time("Pandoc + WebKit Markdown→PDF, long document") {69 let r = try await convert(md, .markdown, .pdf)70 return "\(PDFDocument(url: r.file)?.pageCount ?? 0) pages"71 }72 try await time("Pandoc DOCX→EPUB, long document") { _ = try await convert(docx, .docx, .epub); return "" }73 let report = lines.joined(separator: "\n") + "\n"74 try? FileManager.default.createDirectory(atPath: "/tmp/orixdoc", withIntermediateDirectories: true)75 try report.write(toFile: "/tmp/orixdoc/perf.txt", atomically: true, encoding: .utf8)76 print(report)77 }78}79