From e8c7d7d6fd9bb6d79b54ffbb2b793cb2d1a55d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 22 Sep 2015 22:38:03 +0200 Subject: [PATCH] Simplify performance tests --- .../GRDBProfiling/AppDelegate.swift | 23 ++++----- .../Performance/FetchPerformanceTests.swift | 48 ++++++++----------- 2 files changed, 30 insertions(+), 41 deletions(-) diff --git a/GRDB Tests/GRDBProfiling/GRDBProfiling/AppDelegate.swift b/GRDB Tests/GRDBProfiling/GRDBProfiling/AppDelegate.swift index 921b18479..631f8c59f 100644 --- a/GRDB Tests/GRDBProfiling/GRDBProfiling/AppDelegate.swift +++ b/GRDB Tests/GRDBProfiling/GRDBProfiling/AppDelegate.swift @@ -21,23 +21,20 @@ class AppDelegate: NSObject, NSApplicationDelegate { func readFromDatabase() { for _ in 0..<100 { - var sum: Int64 = 0 dbQueue.inDatabase { db in for row in Row.fetch(db, "SELECT * FROM items") { - let i0: Int64 = row.value(atIndex: 0) - let i1: Int64 = row.value(atIndex: 1) - let i2: Int64 = row.value(atIndex: 2) - let i3: Int64 = row.value(atIndex: 3) - let i4: Int64 = row.value(atIndex: 4) - let i5: Int64 = row.value(atIndex: 5) - let i6: Int64 = row.value(atIndex: 6) - let i7: Int64 = row.value(atIndex: 7) - let i8: Int64 = row.value(atIndex: 8) - let i9: Int64 = row.value(atIndex: 9) - sum += i0 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + let _: Int64 = row.value(atIndex: 0) + let _: Int64 = row.value(atIndex: 1) + let _: Int64 = row.value(atIndex: 2) + let _: Int64 = row.value(atIndex: 3) + let _: Int64 = row.value(atIndex: 4) + let _: Int64 = row.value(atIndex: 5) + let _: Int64 = row.value(atIndex: 6) + let _: Int64 = row.value(atIndex: 7) + let _: Int64 = row.value(atIndex: 8) + let _: Int64 = row.value(atIndex: 9) } } - print(sum) } } } diff --git a/GRDB Tests/Performance/FetchPerformanceTests.swift b/GRDB Tests/Performance/FetchPerformanceTests.swift index 84d794a1c..942363be4 100644 --- a/GRDB Tests/Performance/FetchPerformanceTests.swift +++ b/GRDB Tests/Performance/FetchPerformanceTests.swift @@ -22,53 +22,45 @@ class FetchPerformanceTests: XCTestCase { let databasePath = NSBundle(forClass: self.dynamicType).pathForResource("FetchPerformanceTests", ofType: "sqlite")! let dbQueue = try! DatabaseQueue(path: databasePath) - var sum: Int64 = 0 self.measureBlock { - sum = 0 dbQueue.inDatabase { db in for row in Row.fetch(db, "SELECT * FROM items") { - let i0: Int64 = row.value(atIndex: 0) - let i1: Int64 = row.value(atIndex: 1) - let i2: Int64 = row.value(atIndex: 2) - let i3: Int64 = row.value(atIndex: 3) - let i4: Int64 = row.value(atIndex: 4) - let i5: Int64 = row.value(atIndex: 5) - let i6: Int64 = row.value(atIndex: 6) - let i7: Int64 = row.value(atIndex: 7) - let i8: Int64 = row.value(atIndex: 8) - let i9: Int64 = row.value(atIndex: 9) - sum += i0 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + let _: Int64 = row.value(atIndex: 0) + let _: Int64 = row.value(atIndex: 1) + let _: Int64 = row.value(atIndex: 2) + let _: Int64 = row.value(atIndex: 3) + let _: Int64 = row.value(atIndex: 4) + let _: Int64 = row.value(atIndex: 5) + let _: Int64 = row.value(atIndex: 6) + let _: Int64 = row.value(atIndex: 7) + let _: Int64 = row.value(atIndex: 8) + let _: Int64 = row.value(atIndex: 9) } } } - XCTAssertEqual(sum, 1999990) } func testFMDBFetchPerformance() { let databasePath = NSBundle(forClass: self.dynamicType).pathForResource("FetchPerformanceTests", ofType: "sqlite")! let dbQueue = FMDatabaseQueue(path: databasePath) - var sum: Int64 = 0 self.measureBlock { - sum = 0 dbQueue.inDatabase { db in if let rs = db.executeQuery("SELECT * FROM items", withArgumentsInArray: nil) { while rs.next() { - let i0 = rs.longLongIntForColumnIndex(0) - let i1 = rs.longLongIntForColumnIndex(1) - let i2 = rs.longLongIntForColumnIndex(2) - let i3 = rs.longLongIntForColumnIndex(3) - let i4 = rs.longLongIntForColumnIndex(4) - let i5 = rs.longLongIntForColumnIndex(5) - let i6 = rs.longLongIntForColumnIndex(6) - let i7 = rs.longLongIntForColumnIndex(7) - let i8 = rs.longLongIntForColumnIndex(8) - let i9 = rs.longLongIntForColumnIndex(9) - sum += i0 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + let _ = rs.longLongIntForColumnIndex(0) + let _ = rs.longLongIntForColumnIndex(1) + let _ = rs.longLongIntForColumnIndex(2) + let _ = rs.longLongIntForColumnIndex(3) + let _ = rs.longLongIntForColumnIndex(4) + let _ = rs.longLongIntForColumnIndex(5) + let _ = rs.longLongIntForColumnIndex(6) + let _ = rs.longLongIntForColumnIndex(7) + let _ = rs.longLongIntForColumnIndex(8) + let _ = rs.longLongIntForColumnIndex(9) } } } } - XCTAssertEqual(sum, 1999990) } }