aboutsummaryrefslogtreecommitdiff
path: root/Benchmarks
diff options
context:
space:
mode:
authorRuben Beltran del Rio <jj@r.bdr.sh>2025-12-13 01:17:52 +0100
committerRuben Beltran del Rio <jj@r.bdr.sh>2025-12-14 09:15:07 +0100
commit03f1a7389afeadf9aa2b1d62a38e5cb0a2a7e60d (patch)
tree2efefc34a61c62d55d8436180acfc3590287f5fd /Benchmarks
Initial implementation
Diffstat (limited to 'Benchmarks')
-rw-r--r--Benchmarks/ParseBenchmarkTarget/ParseBenchmarkTarget.swift48
1 files changed, 48 insertions, 0 deletions
diff --git a/Benchmarks/ParseBenchmarkTarget/ParseBenchmarkTarget.swift b/Benchmarks/ParseBenchmarkTarget/ParseBenchmarkTarget.swift
new file mode 100644
index 0000000..c99814f
--- /dev/null
+++ b/Benchmarks/ParseBenchmarkTarget/ParseBenchmarkTarget.swift
@@ -0,0 +1,48 @@
+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(parse(exampleSource))
+ }
+ }
+
+ return Benchmark("parse huge") { benchmark in
+ for _ in benchmark.scaledIterations {
+ blackHole(parse(hugeSource))
+ }
+ }
+}