mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-23 12:30:00 +00:00
[Swift] Migrates struct write APIS to write directly to the buffer (#6093)
* Migrates struct write APIS to in place APIS * Fixes indentation in grpc swift
This commit is contained in:
@@ -60,6 +60,34 @@ func createDocument(Benchmarks: [Benchmark]) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
@inlinable func benchmarkThreeMillionStructs() {
|
||||
let structCount = 3_000_000
|
||||
|
||||
let rawSize = ((16 * 5) * structCount) / 1024
|
||||
|
||||
var fb = FlatBufferBuilder(initialSize: Int32(rawSize * 1600))
|
||||
|
||||
var offsets: [Offset<UOffset>] = []
|
||||
for _ in 0..<structCount {
|
||||
fb.startVectorOfStructs(count: 5, size: 16, alignment: 8)
|
||||
for _ in 0..<5 {
|
||||
fb.createStructOf(size: 16, alignment: 8)
|
||||
fb.reverseAdd(v: 2.4, postion: 0)
|
||||
fb.reverseAdd(v: 2.4, postion: 8)
|
||||
fb.endStruct()
|
||||
}
|
||||
let vector = fb.endVectorOfStructs(count: 5)
|
||||
let start = fb.startTable(with: 1)
|
||||
fb.add(offset: vector, at: 4)
|
||||
offsets.append(Offset<UOffset>(offset: fb.endTable(at: start)))
|
||||
}
|
||||
let vector = fb.createVector(ofOffsets: offsets)
|
||||
let start = fb.startTable(with: 1)
|
||||
fb.add(offset: vector, at: 4)
|
||||
let root = Offset<UOffset>(offset: fb.endTable(at: start))
|
||||
fb.finish(offset: root)
|
||||
}
|
||||
|
||||
func benchmark(numberOfRuns runs: Int) {
|
||||
var benchmarks: [Benchmark] = []
|
||||
let str = (0...99).map { _ -> String in return "x" }.joined()
|
||||
@@ -68,6 +96,7 @@ func benchmark(numberOfRuns runs: Int) {
|
||||
let hundredStr = run(name: "100 str", runs: runs) {
|
||||
create100Strings(str: str)
|
||||
}
|
||||
benchmarks.append(run(name: "3M strc", runs: 1, action: benchmarkThreeMillionStructs))
|
||||
benchmarks.append(hundredStr)
|
||||
print(createDocument(Benchmarks: benchmarks))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user