Skip to content

Commit

Permalink
Moves swift Benchmarks folder from /tests to /benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
mustiikhalil committed Nov 21, 2023
1 parent 1310f14 commit 43f21b3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,33 @@ let benchmarks = {
AA(a: 2.4, b: 2.4),
]

let metrics: [BenchmarkMetric] = [.cpuTotal, .wallClock, .mallocCountTotal, .releaseCount, .peakMemoryResident]
let metrics: [BenchmarkMetric] = [
.cpuTotal,
.wallClock,
.mallocCountTotal,
.releaseCount,
.peakMemoryResident,
]
let maxIterations = 1_000_000
let maxDuration: Duration = .seconds(3)
let singleConfiguration: Benchmark.Configuration = .init(
metrics: metrics,
warmupIterations: 1,
scalingFactor: .one,
maxDuration: maxDuration,
maxIterations: maxIterations)
metrics: metrics,
warmupIterations: 1,
scalingFactor: .one,
maxDuration: maxDuration,
maxIterations: maxIterations)
let kiloConfiguration: Benchmark.Configuration = .init(
metrics: metrics,
warmupIterations: 1,
scalingFactor: .kilo,
maxDuration: maxDuration,
maxIterations: maxIterations)
metrics: metrics,
warmupIterations: 1,
scalingFactor: .kilo,
maxDuration: maxDuration,
maxIterations: maxIterations)
let megaConfiguration: Benchmark.Configuration = .init(
metrics: metrics,
warmupIterations: 1,
scalingFactor: .mega,
maxDuration: maxDuration,
maxIterations: maxIterations)
metrics: metrics,
warmupIterations: 1,
scalingFactor: .mega,
maxDuration: maxDuration,
maxIterations: maxIterations)

Benchmark.defaultConfiguration = megaConfiguration

Expand All @@ -71,63 +77,74 @@ let benchmarks = {
}
}

Benchmark("Clearing 1GB", configuration: singleConfiguration) { benchmark in
var fb = FlatBufferBuilder(initialSize: 1_024_000_000)
benchmark.startMeasurement()
for _ in benchmark.scaledIterations {
blackHole(fb.clear())
}
}

Benchmark("Strings 10") { benchmark in
var fb = FlatBufferBuilder(initialSize: 1<<20)
benchmark.startMeasurement()
for _ in benchmark.scaledIterations {
blackHole(fb.create(string: str10))
blackHole(fb.create(string: str10))
}
}

Benchmark("Strings 100") { benchmark in
var fb = FlatBufferBuilder(initialSize: 1<<20)
benchmark.startMeasurement()
for _ in benchmark.scaledIterations {
blackHole(fb.create(string: str100))
blackHole(fb.create(string: str100))
}
}

Benchmark("Vector 1 Bytes") { benchmark in
var fb = FlatBufferBuilder(initialSize: 1<<20)
benchmark.startMeasurement()
for _ in benchmark.scaledIterations {
blackHole(fb.createVector(bytes: bytes))
blackHole(fb.createVector(bytes: bytes))
}
}

Benchmark("Vector 1 Ints") { benchmark in
var fb = FlatBufferBuilder(initialSize: 1<<20)
benchmark.startMeasurement()
for _ in benchmark.scaledIterations {
blackHole(fb.createVector(ints))
blackHole(fb.createVector(ints))
}
}

Benchmark("Vector 100 Ints") { benchmark in
var fb = FlatBufferBuilder(initialSize: 1<<20)
benchmark.startMeasurement()
for i in benchmark.scaledIterations {
blackHole(fb.createVector(ints))
blackHole(fb.createVector(ints))
}
}

Benchmark("Vector 100 Bytes") { benchmark in
var fb = FlatBufferBuilder(initialSize: 1<<20)
benchmark.startMeasurement()
for i in benchmark.scaledIterations {
blackHole(fb.createVector(bytes))
blackHole(fb.createVector(bytes))
}
}

Benchmark("Vector 100 ContiguousBytes") { benchmark in
var fb = FlatBufferBuilder(initialSize: 1<<20)
benchmark.startMeasurement()
for i in benchmark.scaledIterations {
blackHole(fb.createVector(bytes: bytes))
blackHole(fb.createVector(bytes: bytes))
}
}

Benchmark("FlatBufferBuilder Add", configuration: kiloConfiguration) { benchmark in
Benchmark(
"FlatBufferBuilder Add",
configuration: kiloConfiguration)
{ benchmark in
var fb = FlatBufferBuilder(initialSize: 1024 * 1024 * 32)
benchmark.startMeasurement()
for _ in benchmark.scaledIterations {
Expand All @@ -148,11 +165,11 @@ let benchmarks = {

benchmark.startMeasurement()
for _ in benchmark.scaledIterations {
let vector = fb.createVector(
ofStructs: array)
let start = fb.startTable(with: 1)
fb.add(offset: vector, at: 4)
offsets.append(Offset(offset: fb.endTable(at: start)))
let vector = fb.createVector(
ofStructs: array)
let start = fb.startTable(with: 1)
fb.add(offset: vector, at: 4)
offsets.append(Offset(offset: fb.endTable(at: start)))
}

let vector = fb.createVector(ofOffsets: offsets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let package = Package(
.macOS(.v13),
],
dependencies: [
.package(path: "../../.."),
.package(path: "../.."),
.package(
url: "https://github.com/ordo-one/package-benchmark",
from: "1.12.0"),
Expand Down
File renamed without changes.

0 comments on commit 43f21b3

Please sign in to comment.