Cleanup and cursor profiling tests

This commit is contained in:
Gwendal Roué committed 2022-01-14 18:25:30 +01:00
1 parent 3eea2967b3
commit 549f7ec66e
2 files changed
+117 -6

No files matched your search

-6
View File
@@ -293,7 +293,6 @@ public final class Statement {
///
/// This method is unable to deal with statements that need a specific
/// authorizer. See `forEachStep(_:)`.
@inline(__always)
@usableFromInline
func step<Element>(_ body: (SQLiteStatement) throws -> Element) throws -> Element? {
// This check takes 0 time when profiled. It is, practically speaking, free.
@@ -330,7 +329,6 @@ public final class Statement {
/// 2. `Array(T.fetchCursor(...))` calls `Cursor.forEach(...)`
/// 3. `DatabaseCursor.forEach(...)` calls `Statement.forEachStep(...)`
/// 4. `Statement.forEachStep(...)` deals with the eventual authorizer.
@inline(__always)
@usableFromInline
func forEachStep(_ body: (SQLiteStatement) throws -> Void) throws {
guard sqlite3_stmt_busy(sqliteStatement) == 0 else {
@@ -348,7 +346,6 @@ public final class Statement {
/// Implementation detail of `forEach(_:)`.
/// Does not check for sqlite3_stmt_busy and eventual authorizer.
@inline(__always)
@usableFromInline
func uncheckedForEach(_ body: (SQLiteStatement) throws -> Void) throws {
while true {
@@ -421,7 +418,6 @@ public protocol DatabaseCursor: _DatabaseCursor {
}
extension DatabaseCursor {
@inline(__always)
@inlinable
public func next() throws -> Element? {
if _isDone {
@@ -437,7 +433,6 @@ extension DatabaseCursor {
// Specific implementation of `forEach` in order to deal with
// <https://github.com/groue/GRDB.swift/issues/1124>.
// See `Statement.forEachStep(_:)` for more information.
@inline(__always)
@inlinable
public func forEach(_ body: (Element) throws -> Void) throws {
try statement.forEachStep { try body(_element(sqliteStatement: $0)) }
@@ -471,7 +466,6 @@ final class StatementCursor: DatabaseCursor {
try? statement.reset()
}
@inline(__always)
@usableFromInline
func _element(sqliteStatement: SQLiteStatement) throws { }
}
+117
View File
@@ -166,4 +166,121 @@ class DatabaseCursorTests: GRDBTestCase {
// sqlite3_close_v2(connection)
// }
}
// For profiling tests
let profilingSQL = """
WITH RECURSIVE
cnt(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM cnt WHERE x<10000000)
SELECT x FROM cnt
"""
// Profiling test
func testRowCursorStep() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
let cursor: RowCursor = try Row.fetchCursor(db, sql: profilingSQL)
while let _ = try cursor.next() { }
}
}
// Profiling test
func testRowCursorForEach() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
let cursor: RowCursor = try Row.fetchCursor(db, sql: profilingSQL)
try cursor.forEach { _ in }
}
}
// Profiling test
func testDatabaseValueCursorStep() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
let cursor: DatabaseValueCursor<Int> = try Int.fetchCursor(db, sql: profilingSQL)
while let _ = try cursor.next() { }
}
}
// Profiling test
func testDatabaseValueCursorForEach() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
let cursor: DatabaseValueCursor<Int> = try Int.fetchCursor(db, sql: profilingSQL)
try cursor.forEach { _ in }
}
}
// Profiling test
func testNullableDatabaseValueCursorStep() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
let cursor: NullableDatabaseValueCursor<Int> = try Optional<Int>.fetchCursor(db, sql: profilingSQL)
while let _ = try cursor.next() { }
}
}
// Profiling test
func testNullableDatabaseValueCursorForEach() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
let cursor: NullableDatabaseValueCursor<Int> = try Optional<Int>.fetchCursor(db, sql: profilingSQL)
try cursor.forEach { _ in }
}
}
// Profiling test
func testFastDatabaseValueCursorStep() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
let cursor: FastDatabaseValueCursor<Int> = try Int.fetchCursor(db, sql: profilingSQL)
while let _ = try cursor.next() { }
}
}
// Profiling test
func testFastDatabaseValueCursorForEach() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
let cursor: FastDatabaseValueCursor<Int> = try Int.fetchCursor(db, sql: profilingSQL)
try cursor.forEach { _ in }
}
}
// Profiling test
func testFastNullableDatabaseValueCursorStep() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
let cursor: FastNullableDatabaseValueCursor<Int> = try Optional<Int>.fetchCursor(db, sql: profilingSQL)
while let _ = try cursor.next() { }
}
}
// Profiling test
func testFastNullableDatabaseValueCursorForEach() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
let cursor: FastNullableDatabaseValueCursor<Int> = try Optional<Int>.fetchCursor(db, sql: profilingSQL)
try cursor.forEach { _ in }
}
}
// Profiling test
func testRecordCursorStep() throws {
struct S: FetchableRecord { init(row: Row) { } }
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
let cursor: RecordCursor<S> = try S.fetchCursor(db, sql: profilingSQL)
while let _ = try cursor.next() { }
}
}
// Profiling test
func testRecordCursorForEach() throws {
struct S: FetchableRecord { init(row: Row) { } }
let dbQueue = try makeDatabaseQueue()
try dbQueue.read { db in
let cursor: RecordCursor<S> = try S.fetchCursor(db, sql: profilingSQL)
try cursor.forEach { _ in }
}
}
}