diff --git a/Tests/Performance/GRDBPerformance/FetchNamedValuesTests.swift b/Tests/Performance/GRDBPerformance/FetchNamedValuesTests.swift index 77adee3cf..eda7f0767 100644 --- a/Tests/Performance/GRDBPerformance/FetchNamedValuesTests.swift +++ b/Tests/Performance/GRDBPerformance/FetchNamedValuesTests.swift @@ -10,8 +10,9 @@ private let expectedRowCount = 100_000 class FetchNamedValuesTests: XCTestCase { func testGRDB() throws { - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let dbQueue = try DatabaseQueue(path: databasePath) + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBPerformanceTests.sqlite") + try generateSQLiteDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) + let dbQueue = try DatabaseQueue(path: url.path) measure { var count = 0 @@ -39,9 +40,10 @@ class FetchNamedValuesTests: XCTestCase { } #if GRDB_COMPARE - func testFMDB() { - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let dbQueue = FMDatabaseQueue(path: databasePath)! + func testFMDB() throws { + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBPerformanceTests.sqlite") + try generateSQLiteDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) + let dbQueue = FMDatabaseQueue(path: url.path)! measure { var count = 0 @@ -69,8 +71,9 @@ class FetchNamedValuesTests: XCTestCase { } func testSQLiteSwift() throws { - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let db = try Connection(databasePath) + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBPerformanceTests.sqlite") + try generateSQLiteDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) + let db = try Connection(url.path) measure { var count = 0 diff --git a/Tests/Performance/GRDBPerformance/FetchPositionalValuesTests.swift b/Tests/Performance/GRDBPerformance/FetchPositionalValuesTests.swift index e8bb430e6..610cf2cd2 100644 --- a/Tests/Performance/GRDBPerformance/FetchPositionalValuesTests.swift +++ b/Tests/Performance/GRDBPerformance/FetchPositionalValuesTests.swift @@ -9,10 +9,11 @@ private let expectedRowCount = 100_000 /// Here we test the extraction of values by column index. class FetchPositionalValuesTests: XCTestCase { - func testSQLite() { - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! + func testSQLite() throws { + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBPerformanceTests.sqlite") + try generateSQLiteDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) var connection: OpaquePointer? = nil - sqlite3_open_v2(databasePath, &connection, 0x00000004 /*SQLITE_OPEN_CREATE*/ | 0x00000002 /*SQLITE_OPEN_READWRITE*/, nil) + sqlite3_open_v2(url.path, &connection, 0x00000004 /*SQLITE_OPEN_CREATE*/ | 0x00000002 /*SQLITE_OPEN_READWRITE*/, nil) measure { var count = 0 @@ -51,8 +52,9 @@ class FetchPositionalValuesTests: XCTestCase { } func testGRDB() throws { - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let dbQueue = try DatabaseQueue(path: databasePath) + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBPerformanceTests.sqlite") + try generateSQLiteDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) + let dbQueue = try DatabaseQueue(path: url.path) measure { var count = 0 @@ -80,9 +82,10 @@ class FetchPositionalValuesTests: XCTestCase { } #if GRDB_COMPARE - func testFMDB() { - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let dbQueue = FMDatabaseQueue(path: databasePath)! + func testFMDB() throws { + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBPerformanceTests.sqlite") + try generateSQLiteDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) + let dbQueue = FMDatabaseQueue(path: url.path)! measure { var count = 0 @@ -110,8 +113,9 @@ class FetchPositionalValuesTests: XCTestCase { } func testSQLiteSwift() throws { - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let db = try Connection(databasePath) + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBPerformanceTests.sqlite") + try generateSQLiteDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) + let db = try Connection(url.path) measure { var count = 0 diff --git a/Tests/Performance/GRDBPerformance/FetchRecordClassTests.swift b/Tests/Performance/GRDBPerformance/FetchRecordClassTests.swift index b0c7c94ee..67230aece 100644 --- a/Tests/Performance/GRDBPerformance/FetchRecordClassTests.swift +++ b/Tests/Performance/GRDBPerformance/FetchRecordClassTests.swift @@ -11,8 +11,9 @@ private let expectedRowCount = 100_000 class FetchRecordClassTests: XCTestCase { func testGRDB() throws { - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let dbQueue = try DatabaseQueue(path: databasePath) + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBPerformanceTests.sqlite") + try generateSQLiteDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) + let dbQueue = try DatabaseQueue(path: url.path) measure { let items = try! dbQueue.inDatabase { db in @@ -27,11 +28,12 @@ class FetchRecordClassTests: XCTestCase { #if GRDB_COMPARE func testCoreData() throws { - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceCoreDataTests", ofType: "sqlite")! let modelURL = Bundle(for: type(of: self)).url(forResource: "PerformanceModel", withExtension: "momd")! + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBCoreDataPerformanceTests.sqlite") + try generateCoreDataDatabaseIfMissing(at: url, fromModelAt: modelURL, insertedRowCount: expectedRowCount) let mom = NSManagedObjectModel(contentsOf: modelURL)! let psc = NSPersistentStoreCoordinator(managedObjectModel: mom) - try psc.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: URL(fileURLWithPath: databasePath), options: nil) + try psc.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil) let moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType) moc.persistentStoreCoordinator = psc @@ -56,8 +58,9 @@ class FetchRecordClassTests: XCTestCase { } func testRealm() throws { - let databaseURL = Bundle(for: type(of: self)).url(forResource: "PerformanceRealmTests", withExtension: "realm")! - let realm = try Realm(fileURL: databaseURL) + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBRealmPerformanceTests.realm") + try generateRealmDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) + let realm = try Realm(fileURL: url) measure { let items = realm.objects(RealmItem.self) diff --git a/Tests/Performance/GRDBPerformance/FetchRecordCodableTests.swift b/Tests/Performance/GRDBPerformance/FetchRecordCodableTests.swift index 73f0729ca..c08d45cf2 100644 --- a/Tests/Performance/GRDBPerformance/FetchRecordCodableTests.swift +++ b/Tests/Performance/GRDBPerformance/FetchRecordCodableTests.swift @@ -10,8 +10,9 @@ private let expectedRowCount = 100_000 class FetchRecordCodableTests: XCTestCase { func testGRDB() throws { - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let dbQueue = try DatabaseQueue(path: databasePath) + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBPerformanceTests.sqlite") + try generateSQLiteDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) + let dbQueue = try DatabaseQueue(path: url.path) measure { let items = try! dbQueue.inDatabase { db in diff --git a/Tests/Performance/GRDBPerformance/FetchRecordStructTests.swift b/Tests/Performance/GRDBPerformance/FetchRecordStructTests.swift index 869e3a490..433b917e9 100644 --- a/Tests/Performance/GRDBPerformance/FetchRecordStructTests.swift +++ b/Tests/Performance/GRDBPerformance/FetchRecordStructTests.swift @@ -9,10 +9,11 @@ private let expectedRowCount = 100_000 /// Here we test the extraction of models from rows class FetchRecordStructTests: XCTestCase { - func testSQLite() { - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! + func testSQLite() throws { + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBPerformanceTests.sqlite") + try generateSQLiteDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) var connection: OpaquePointer? = nil - sqlite3_open_v2(databasePath, &connection, 0x00000004 /*SQLITE_OPEN_CREATE*/ | 0x00000002 /*SQLITE_OPEN_READWRITE*/, nil) + sqlite3_open_v2(url.path, &connection, 0x00000004 /*SQLITE_OPEN_CREATE*/ | 0x00000002 /*SQLITE_OPEN_READWRITE*/, nil) measure { var statement: OpaquePointer? = nil @@ -66,8 +67,9 @@ class FetchRecordStructTests: XCTestCase { } func testGRDB() throws { - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let dbQueue = try DatabaseQueue(path: databasePath) + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBPerformanceTests.sqlite") + try generateSQLiteDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) + let dbQueue = try DatabaseQueue(path: url.path) measure { let items = try! dbQueue.inDatabase { db in @@ -81,11 +83,12 @@ class FetchRecordStructTests: XCTestCase { } #if GRDB_COMPARE - func testFMDB() { + func testFMDB() throws { // Here we test the loading of an array of Records. - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let dbQueue = FMDatabaseQueue(path: databasePath)! + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBPerformanceTests.sqlite") + try generateSQLiteDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) + let dbQueue = FMDatabaseQueue(path: url.path)! measure { var items = [ItemStruct]() @@ -104,8 +107,9 @@ class FetchRecordStructTests: XCTestCase { } func testSQLiteSwift() throws { - let databasePath = Bundle(for: type(of: self)).path(forResource: "PerformanceTests", ofType: "sqlite")! - let db = try Connection(databasePath) + let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("GRDBPerformanceTests.sqlite") + try generateSQLiteDatabaseIfMissing(at: url, insertedRowCount: expectedRowCount) + let db = try Connection(url.path) measure { var items = [ItemStruct]() diff --git a/Tests/Performance/GRDBPerformance/GRDBPerformance.xcodeproj/project.pbxproj b/Tests/Performance/GRDBPerformance/GRDBPerformance.xcodeproj/project.pbxproj index 17a196df8..b836dbeef 100755 --- a/Tests/Performance/GRDBPerformance/GRDBPerformance.xcodeproj/project.pbxproj +++ b/Tests/Performance/GRDBPerformance/GRDBPerformance.xcodeproj/project.pbxproj @@ -22,10 +22,8 @@ 56439B3E1F4CA1DC0066043F /* PerformanceModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B2D1C42B23B00861EB8 /* PerformanceModel.xcdatamodeld */; }; 56439B3F1F4CA1DC0066043F /* FetchPositionalValuesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B291C4130AF00861EB8 /* FetchPositionalValuesTests.swift */; }; 56439B431F4CA1DC0066043F /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 56DE7B341C42B37E00861EB8 /* CoreData.framework */; }; - 56439B471F4CA1DC0066043F /* PerformanceRealmTests.realm in Resources */ = {isa = PBXBuildFile; fileRef = 563363F81C960711000BE133 /* PerformanceRealmTests.realm */; }; - 56439B481F4CA1DC0066043F /* PerformanceTests.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 56BB86111BA9886D001F9168 /* PerformanceTests.sqlite */; }; - 56439B491F4CA1DC0066043F /* PerformanceCoreDataTests.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 56DE7B361C42BBBB00861EB8 /* PerformanceCoreDataTests.sqlite */; }; - 56439B581F4CA5AE0066043F /* PerformanceTests.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 56BB86111BA9886D001F9168 /* PerformanceTests.sqlite */; }; + 565BC5E82517645D00D2B53E /* Generation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565BC5E72517645D00D2B53E /* Generation.swift */; }; + 565BC5E92517645D00D2B53E /* Generation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565BC5E72517645D00D2B53E /* Generation.swift */; }; 56707201208A509C006AD95A /* DateParsingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567071FA208A509C006AD95A /* DateParsingTests.swift */; }; 5679870223A37A6A0076902D /* GRDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 567986B923A378CD0076902D /* GRDB.framework */; }; 5679870523A37A790076902D /* GRDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 567986B923A378CD0076902D /* GRDB.framework */; }; @@ -131,13 +129,12 @@ /* Begin PBXFileReference section */ 560C981A1C0E22D300BF8471 /* GRDBOSXPerformanceTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBOSXPerformanceTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 563363F81C960711000BE133 /* PerformanceRealmTests.realm */ = {isa = PBXFileReference; lastKnownFileType = file; path = PerformanceRealmTests.realm; sourceTree = ""; }; 56439B501F4CA1DC0066043F /* GRDBOSXPerformanceComparisonTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBOSXPerformanceComparisonTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 565BC5E72517645D00D2B53E /* Generation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Generation.swift; sourceTree = ""; }; 567071FA208A509C006AD95A /* DateParsingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateParsingTests.swift; sourceTree = ""; }; 567986AD23A378CD0076902D /* GRDB.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GRDB.xcodeproj; path = ../../../GRDB.xcodeproj; sourceTree = ""; }; 5690AFD72120589A001530EA /* InsertRecordCodableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InsertRecordCodableTests.swift; sourceTree = ""; }; 5690AFDA212058CB001530EA /* FetchRecordCodableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRecordCodableTests.swift; sourceTree = ""; }; - 56BB86111BA9886D001F9168 /* PerformanceTests.sqlite */ = {isa = PBXFileReference; lastKnownFileType = file; path = PerformanceTests.sqlite; sourceTree = ""; }; 56BB86121BA9886D001F9168 /* InsertRecordClassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InsertRecordClassTests.swift; sourceTree = ""; }; 56BB862D1BA98933001F9168 /* GRDBPerformanceComparisonTests-Bridging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GRDBPerformanceComparisonTests-Bridging.h"; sourceTree = ""; }; 56CA22211BB41565009A04C5 /* PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerformanceTests.swift; sourceTree = ""; }; @@ -150,7 +147,6 @@ 56DE7B2B1C41311900861EB8 /* FetchRecordClassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRecordClassTests.swift; sourceTree = ""; }; 56DE7B2E1C42B23B00861EB8 /* PerformanceModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = PerformanceModel.xcdatamodel; sourceTree = ""; }; 56DE7B341C42B37E00861EB8 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; - 56DE7B361C42BBBB00861EB8 /* PerformanceCoreDataTests.sqlite */ = {isa = PBXFileReference; lastKnownFileType = file; path = PerformanceCoreDataTests.sqlite; sourceTree = ""; }; DC37740419C8CBB3004FCF85 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; /* End PBXFileReference section */ @@ -205,16 +201,14 @@ isa = PBXGroup; children = ( 56BB862D1BA98933001F9168 /* GRDBPerformanceComparisonTests-Bridging.h */, - 56BB86111BA9886D001F9168 /* PerformanceTests.sqlite */, - 56DE7B361C42BBBB00861EB8 /* PerformanceCoreDataTests.sqlite */, 56DE7B2D1C42B23B00861EB8 /* PerformanceModel.xcdatamodeld */, - 563363F81C960711000BE133 /* PerformanceRealmTests.realm */, 567071FA208A509C006AD95A /* DateParsingTests.swift */, 56DE7B271C41302500861EB8 /* FetchNamedValuesTests.swift */, 56DE7B291C4130AF00861EB8 /* FetchPositionalValuesTests.swift */, 56DE7B2B1C41311900861EB8 /* FetchRecordClassTests.swift */, 5690AFDA212058CB001530EA /* FetchRecordCodableTests.swift */, 56D3BE701F4EB1900034C6D2 /* FetchRecordStructTests.swift */, + 565BC5E72517645D00D2B53E /* Generation.swift */, 56DE7B251C412FDA00861EB8 /* InsertNamedValuesTests.swift */, 56DE7B231C412F7E00861EB8 /* InsertPositionalValuesTests.swift */, 56BB86121BA9886D001F9168 /* InsertRecordClassTests.swift */, @@ -409,7 +403,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 56439B581F4CA5AE0066043F /* PerformanceTests.sqlite in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -417,9 +410,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 56439B471F4CA1DC0066043F /* PerformanceRealmTests.realm in Resources */, - 56439B481F4CA1DC0066043F /* PerformanceTests.sqlite in Resources */, - 56439B491F4CA1DC0066043F /* PerformanceCoreDataTests.sqlite in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -431,6 +421,7 @@ buildActionMask = 2147483647; files = ( 56D3BE711F4EB1A00034C6D2 /* FetchRecordStructTests.swift in Sources */, + 565BC5E82517645D00D2B53E /* Generation.swift in Sources */, 560C98231C0E23BB00BF8471 /* InsertRecordClassTests.swift in Sources */, 56707201208A509C006AD95A /* DateParsingTests.swift in Sources */, 56DE7B2C1C41311900861EB8 /* FetchRecordClassTests.swift in Sources */, @@ -450,6 +441,7 @@ buildActionMask = 2147483647; files = ( 56439B341F4CA1DC0066043F /* InsertRecordClassTests.swift in Sources */, + 565BC5E92517645D00D2B53E /* Generation.swift in Sources */, 56439B361F4CA1DC0066043F /* FetchRecordClassTests.swift in Sources */, 56439B381F4CA1DC0066043F /* FetchNamedValuesTests.swift in Sources */, 56439B391F4CA1DC0066043F /* InsertPositionalValuesTests.swift in Sources */, @@ -494,7 +486,7 @@ "@executable_path/../Frameworks", "@loader_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBOSXTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; @@ -516,7 +508,7 @@ "@executable_path/../Frameworks", "@loader_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBOSXTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; @@ -538,7 +530,7 @@ "@executable_path/../Frameworks", "@loader_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.11; OTHER_SWIFT_FLAGS = "$(inherited) -D GRDB_COMPARE"; PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBOSXTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -561,7 +553,7 @@ "@executable_path/../Frameworks", "@loader_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.11; OTHER_SWIFT_FLAGS = "$(inherited) -D GRDB_COMPARE"; PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBOSXTests; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Tests/Performance/GRDBPerformance/Generation.swift b/Tests/Performance/GRDBPerformance/Generation.swift new file mode 100644 index 000000000..ebef93f26 --- /dev/null +++ b/Tests/Performance/GRDBPerformance/Generation.swift @@ -0,0 +1,72 @@ +import XCTest +import Foundation +import GRDB +#if GRDB_COMPARE +import CoreData +import RealmSwift +#endif + +func generateSQLiteDatabaseIfMissing(at url: URL, insertedRowCount: Int) throws { + try DatabaseQueue(path: url.path).write { db in + if try db.tableExists("items") { + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM items")! + if count == insertedRowCount { + return + } else { + try db.execute(sql: "DROP TABLE items") + } + } + try db.execute(sql: "CREATE TABLE items (i0 INT, i1 INT, i2 INT, i3 INT, i4 INT, i5 INT, i6 INT, i7 INT, i8 INT, i9 INT)") + + let statement = try! db.makeUpdateStatement(sql: "INSERT INTO items (i0, i1, i2, i3, i4, i5, i6, i7, i8, i9) VALUES (?,?,?,?,?,?,?,?,?,?)") + for i in 0..(entityName: "Item") + if try! moc.count(for: request) == insertedRowCount { + return + } + try! moc.execute(NSBatchDeleteRequest(fetchRequest: request)) + + for i in 0..