mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-25 04:46:13 +00:00
[Swift] Migrating benchmarks to a newer lib. (#8168)
* Adds Nativestructs pointer push into ByteBuffer Updates benchmarks & cleanup Adds native struct vector tests * Address PR comments * Add more benchmarks * Some benchmark cleanup * Return back to 1M structs * Tweak Structs benchmark * Moves swift Benchmarks folder from /tests to /benchmarks --------- Co-authored-by: Joakim Hassila <jocke@ordo.one>
This commit is contained in:
@@ -67,9 +67,9 @@ final class FlatBuffersNanInfTests: XCTestCase {
|
||||
let data = try encoder.encode(reader)
|
||||
let decoder = JSONDecoder()
|
||||
decoder.nonConformingFloatDecodingStrategy = .convertFromString(
|
||||
positiveInfinity: "inf",
|
||||
negativeInfinity: "-inf",
|
||||
nan: "nan")
|
||||
positiveInfinity: "inf",
|
||||
negativeInfinity: "-inf",
|
||||
nan: "nan")
|
||||
decoder.keyDecodingStrategy = .convertFromSnakeCase
|
||||
let value = try decoder.decode(Test.self, from: data)
|
||||
XCTAssertEqual(value.value, 100)
|
||||
|
||||
@@ -53,6 +53,26 @@ final class FlatBuffersVectors: XCTestCase {
|
||||
// swiftformat:enable all
|
||||
}
|
||||
|
||||
func testCreateStructArray() {
|
||||
struct Vec: NativeStruct {
|
||||
let x, y, z: Float32
|
||||
}
|
||||
let vector: [Vec] = [
|
||||
Vec(x: 1, y: 2, z: 3),
|
||||
Vec(x: 4, y: 5, z: 6),
|
||||
Vec(x: 7, y: 8, z: 9),
|
||||
]
|
||||
var b = FlatBufferBuilder(initialSize: 100)
|
||||
let o = b.createVector(ofStructs: vector)
|
||||
b.finish(offset: o)
|
||||
vector.withUnsafeBytes { pointer in
|
||||
print(Array(pointer))
|
||||
}
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(b.sizedByteArray, [4, 0, 0, 0, 3, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 128, 64, 0, 0, 160, 64, 0, 0, 192, 64, 0, 0, 224, 64, 0, 0, 0, 65, 0, 0, 16, 65])
|
||||
// swiftformat:enable all
|
||||
}
|
||||
|
||||
func testCreateEmptyIntArray() {
|
||||
let numbers: [Int32] = []
|
||||
var b = FlatBufferBuilder(initialSize: 20)
|
||||
|
||||
Reference in New Issue
Block a user