From ce41eba9969ca9ffc4ace5a189d6987269b507f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 17 Dec 2015 09:59:11 +0100 Subject: [PATCH] GRDBProfiling WIP --- .../GRDBProfiling/AppDelegate.swift | 82 +++++++++---------- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/GRDB Tests/GRDBProfiling/GRDBProfiling/AppDelegate.swift b/GRDB Tests/GRDBProfiling/GRDBProfiling/AppDelegate.swift index ca8bfbbcd..6d2b74523 100644 --- a/GRDB Tests/GRDBProfiling/GRDBProfiling/AppDelegate.swift +++ b/GRDB Tests/GRDBProfiling/GRDBProfiling/AppDelegate.swift @@ -23,67 +23,59 @@ class AppDelegate: NSObject, NSApplicationDelegate { } func testValueAtIndexPerformance() { - for _ in 0..<10 { - dbQueue.inDatabase { db in - for row in Row.fetch(db, "SELECT * FROM items") { - let _: Int = row.value(atIndex: 0) - let _: Int = row.value(atIndex: 1) - let _: Int = row.value(atIndex: 2) - let _: Int = row.value(atIndex: 3) - let _: Int = row.value(atIndex: 4) - let _: Int = row.value(atIndex: 5) - let _: Int = row.value(atIndex: 6) - let _: Int = row.value(atIndex: 7) - let _: Int = row.value(atIndex: 8) - let _: Int = row.value(atIndex: 9) - } + dbQueue.inDatabase { db in + for row in Row.fetch(db, "SELECT * FROM items") { + let _: Int = row.value(atIndex: 0) + let _: Int = row.value(atIndex: 1) + let _: Int = row.value(atIndex: 2) + let _: Int = row.value(atIndex: 3) + let _: Int = row.value(atIndex: 4) + let _: Int = row.value(atIndex: 5) + let _: Int = row.value(atIndex: 6) + let _: Int = row.value(atIndex: 7) + let _: Int = row.value(atIndex: 8) + let _: Int = row.value(atIndex: 9) } } } func testValueNamedPerformance() { - for _ in 0..<10 { - dbQueue.inDatabase { db in - for row in Row.fetch(db, "SELECT * FROM items") { - let _: Int = row.value(named: "i0") - let _: Int = row.value(named: "i1") - let _: Int = row.value(named: "i2") - let _: Int = row.value(named: "i3") - let _: Int = row.value(named: "i4") - let _: Int = row.value(named: "i5") - let _: Int = row.value(named: "i6") - let _: Int = row.value(named: "i7") - let _: Int = row.value(named: "i8") - let _: Int = row.value(named: "i9") - } + dbQueue.inDatabase { db in + for row in Row.fetch(db, "SELECT * FROM items") { + let _: Int = row.value(named: "i0") + let _: Int = row.value(named: "i1") + let _: Int = row.value(named: "i2") + let _: Int = row.value(named: "i3") + let _: Int = row.value(named: "i4") + let _: Int = row.value(named: "i5") + let _: Int = row.value(named: "i6") + let _: Int = row.value(named: "i7") + let _: Int = row.value(named: "i8") + let _: Int = row.value(named: "i9") } } } func testRecordPerformance() { - for _ in 0..<10 { - let records = dbQueue.inDatabase { db in - PerformanceRecord.fetchAll(db, "SELECT * FROM items") - } - precondition(records[4].i2 == 1) - precondition(records[4].i3 == 0) - precondition(records[5].i2 == 2) - precondition(records[5].i3 == 1) + let records = dbQueue.inDatabase { db in + PerformanceRecord.fetchAll(db, "SELECT * FROM items") } + assert(records[4].i2 == 1) + assert(records[4].i3 == 0) + assert(records[5].i2 == 2) + assert(records[5].i3 == 1) } func testKeyValueCodingPerformance() { - for _ in 0..<10 { - let records = dbQueue.inDatabase { db in - Row.fetch(db, "SELECT * FROM items").map { row in - PerformanceObjCRecord(dictionary: row.toNSDictionary()) - } + let records = dbQueue.inDatabase { db in + Row.fetch(db, "SELECT * FROM items").map { row in + PerformanceObjCRecord(dictionary: row.toNSDictionary()) } - precondition(records[4].i2!.intValue == 1) - precondition(records[4].i3!.intValue == 0) - precondition(records[5].i2!.intValue == 2) - precondition(records[5].i3!.intValue == 1) } + assert(records[4].i2!.intValue == 1) + assert(records[4].i3!.intValue == 0) + assert(records[5].i2!.intValue == 2) + assert(records[5].i3!.intValue == 1) } }