Simplify performance tests

This commit is contained in:
Gwendal Roué committed 2015-09-22 22:38:03 +02:00
1 parent 49c9636086
commit e8c7d7d6fd
2 files changed
+30 -41

No files matched your search

@@ -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)
}
}
}
@@ -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)
}
}