Skip to content

Commit

Permalink
Add sample with multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
hassila committed Jan 10, 2025
1 parent 7087445 commit 18bf9b4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
20 changes: 20 additions & 0 deletions Benchmarks/Miscellaneous/Miscellaneous.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,27 @@ let benchmarks = {
}
}

func performAllocationsMutablePointer(count: Int, size: Int, shouldFree: Bool = true) {
for _ in 0 ..< count {
let x: UnsafeMutablePointer<Int> = UnsafeMutablePointer.allocate(capacity: size)
blackHole(x)
if shouldFree {
free(x)
}
}
}

Benchmark.defaultConfiguration = .init(metrics: .memory + .arc)
Benchmark.defaultConfiguration.maxIterations = 1

Benchmark("Memory leak 123 allocations of 4K - performAllocationsMutablePointer") { _ in
performAllocationsMutablePointer(count: 123, size: 4096, shouldFree: false)
}

Benchmark("Memory leak 1 allocation of 1K") { _ in
let x: UnsafeMutablePointer<Int> = UnsafeMutablePointer.allocate(capacity: 5000)
blackHole(x)
}

Benchmark("Memory leak 123 allocations of 4K") { _ in
performAllocations(count: 123, size: 4096, shouldFree: false)
Expand Down
10 changes: 10 additions & 0 deletions Benchmarks/MultiFileExample/SomeBenchmarks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Benchmark
import Foundation

func addSomeBenchmarks() {
Benchmark("SomeBenchmark") { benchmark in
for _ in benchmark.scaledIterations {
blackHole(Date())
}
}
}
10 changes: 10 additions & 0 deletions Benchmarks/MultiFileExample/SomeMoreBenchmarks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Benchmark
import Foundation

func addSomeMoreBenchmarks() {
Benchmark("SomeMoreBenchmark") { benchmark in
for _ in benchmark.scaledIterations {
blackHole(Date())
}
}
}
14 changes: 7 additions & 7 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ordo-one/package-benchmark",
"state" : {
"revision" : "c53cdcaf09495b61190b86fd031438da8988e60c",
"version" : "1.21.0"
"revision" : "d4909695344b6e1ef88f0a711df6ab8708dd135d",
"version" : "1.27.3"
}
},
{
Expand All @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "c8ed701b513cf5177118a175d85fbbbcd707ab41",
"version" : "1.3.0"
"revision" : "41982a3656a71c768319979febd796c6fd111d5c",
"version" : "1.5.0"
}
},
{
Expand All @@ -48,7 +48,7 @@
{
"identity" : "swift-extras-json",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-extras/swift-extras-json",
"location" : "https://github.com/swift-extras/swift-extras-json.git",
"state" : {
"revision" : "122b9454ef01bf89a4c190b8fd3717ddd0a2fbd0",
"version" : "0.6.0"
Expand All @@ -68,8 +68,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system",
"state" : {
"revision" : "025bcb1165deab2e20d4eaba79967ce73013f496",
"version" : "1.2.1"
"revision" : "d2ba781702a1d8285419c15ee62fd734a9437ff5",
"version" : "1.3.2"
}
},
{
Expand Down
14 changes: 14 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,17 @@ let package = Package(
]
)


// Benchmark of MultiFileExample
package.targets += [
.executableTarget(
name: "MultiFileExample",
dependencies: [
.product(name: "Benchmark", package: "package-benchmark"),
],
path: "Benchmarks/MultiFileExample",
plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
]
),
]

0 comments on commit 18bf9b4

Please sign in to comment.