Add perf hooks for testing substring path. (#1976)

This commit is contained in:
Cory Benfield 2021-10-13 12:08:37 +01:00 committed by GitHub
parent 06cb3dd096
commit d906b890d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -22,8 +22,9 @@ func run(identifier: String) {
}
var buffer = ByteBufferAllocator().buffer(capacity: 7 * 1000)
let foundationData = "A".data(using: .utf8)!
let substring = Substring("A")
@inline(never)
func doWrites(buffer: inout ByteBuffer) {
func doWrites(buffer: inout ByteBuffer, dispatchData: DispatchData, substring: Substring) {
/* these ones are zero allocations */
// buffer.writeBytes(foundationData) // see SR-7542
buffer.writeBytes([0x41])
@ -34,6 +35,9 @@ func run(identifier: String) {
/* those down here should be one allocation each (on Linux) */
buffer.writeBytes(dispatchData) // see https://bugs.swift.org/browse/SR-9597
/* these here are one allocation on all platforms */
buffer.writeSubstring(substring)
}
@inline(never)
func doReads(buffer: inout ByteBuffer) {
@ -54,7 +58,7 @@ func run(identifier: String) {
precondition("A" == str, "\(str!)")
}
for _ in 0..<1000 {
doWrites(buffer: &buffer)
doWrites(buffer: &buffer, dispatchData: dispatchData, substring: substring)
doReads(buffer: &buffer)
}
return buffer.readableBytes

View File

@ -328,8 +328,9 @@ measureAndPrint(desc: "bytebuffer_lots_of_rw") {
DispatchData(bytes: UnsafeRawBufferPointer(start: UnsafeRawPointer(ptr.baseAddress), count: ptr.count))
}
var buffer = ByteBufferAllocator().buffer(capacity: 7 * 1024 * 1024)
let substring = Substring("A")
@inline(never)
func doWrites(buffer: inout ByteBuffer) {
func doWrites(buffer: inout ByteBuffer, dispatchData: DispatchData, substring: Substring) {
/* all of those should be 0 allocations */
// buffer.writeBytes(foundationData) // see SR-7542
@ -339,6 +340,7 @@ measureAndPrint(desc: "bytebuffer_lots_of_rw") {
buffer.writeString("A")
buffer.writeStaticString("A")
buffer.writeInteger(0x41, as: UInt8.self)
buffer.writeSubstring(substring)
}
@inline(never)
func doReads(buffer: inout ByteBuffer) {
@ -359,7 +361,7 @@ measureAndPrint(desc: "bytebuffer_lots_of_rw") {
precondition("A" == str, "\(str!)")
}
for _ in 0 ..< 1024*1024 {
doWrites(buffer: &buffer)
doWrites(buffer: &buffer, dispatchData: dispatchData, substring: substring)
doReads(buffer: &buffer)
}
return buffer.readableBytes