aboutsummaryrefslogtreecommitdiff
path: root/Benchmarks/ParseBenchmarkTarget
diff options
context:
space:
mode:
Diffstat (limited to 'Benchmarks/ParseBenchmarkTarget')
-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))
+ }
+ }
+}