mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
Core Data performance tests
This commit is contained in:
1 parent
52b6a2ecf9
commit
dd2f11988f
5 files changed
+105
-2
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import XCTest
|
||||
import GRDB
|
||||
import SQLite
|
||||
import CoreData
|
||||
|
||||
private let expectedRowCount = 100_000
|
||||
|
||||
@@ -127,4 +128,32 @@ class FetchRecordTests: XCTestCase {
|
||||
XCTAssertEqual(items[expectedRowCount-1].i9, expectedRowCount-1)
|
||||
}
|
||||
}
|
||||
|
||||
func testCoreData() {
|
||||
let databasePath = NSBundle(forClass: self.dynamicType).pathForResource("PerformanceCoreDataTests", ofType: "sqlite")!
|
||||
let modelURL = NSBundle(forClass: self.dynamicType).URLForResource("PerformanceModel", withExtension: "momd")!
|
||||
let mom = NSManagedObjectModel(contentsOfURL: modelURL)!
|
||||
let psc = NSPersistentStoreCoordinator(managedObjectModel: mom)
|
||||
try! psc.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: NSURL(fileURLWithPath: databasePath), options: nil)
|
||||
let moc = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
|
||||
moc.persistentStoreCoordinator = psc
|
||||
|
||||
measureBlock {
|
||||
let request = NSFetchRequest(entityName: "Item")
|
||||
let items = try! moc.executeFetchRequest(request)
|
||||
for item in items {
|
||||
item.valueForKey("i0")
|
||||
item.valueForKey("i1")
|
||||
item.valueForKey("i2")
|
||||
item.valueForKey("i3")
|
||||
item.valueForKey("i4")
|
||||
item.valueForKey("i5")
|
||||
item.valueForKey("i6")
|
||||
item.valueForKey("i7")
|
||||
item.valueForKey("i8")
|
||||
item.valueForKey("i9")
|
||||
}
|
||||
XCTAssertEqual(items.count, expectedRowCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import XCTest
|
||||
import GRDB
|
||||
import CoreData
|
||||
|
||||
private let insertedRowCount = 20_000
|
||||
|
||||
@@ -37,4 +38,34 @@ class InsertRecordTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testCoreData() {
|
||||
let databaseFileName = "GRDBPerformanceTests-\(NSProcessInfo.processInfo().globallyUniqueString).sqlite"
|
||||
let databasePath = (NSTemporaryDirectory() as NSString).stringByAppendingPathComponent(databaseFileName)
|
||||
let modelURL = NSBundle(forClass: self.dynamicType).URLForResource("PerformanceModel", withExtension: "momd")!
|
||||
let mom = NSManagedObjectModel(contentsOfURL: modelURL)!
|
||||
|
||||
measureBlock {
|
||||
let psc = NSPersistentStoreCoordinator(managedObjectModel: mom)
|
||||
let store = try! psc.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: NSURL(fileURLWithPath: databasePath), options: nil)
|
||||
let moc = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
|
||||
moc.persistentStoreCoordinator = psc
|
||||
|
||||
for i in 0..<insertedRowCount {
|
||||
let item = NSEntityDescription.insertNewObjectForEntityForName("Item", inManagedObjectContext: moc)
|
||||
item.setValue(NSNumber(integer: i), forKey: "i0")
|
||||
item.setValue(NSNumber(integer: i), forKey: "i1")
|
||||
item.setValue(NSNumber(integer: i), forKey: "i2")
|
||||
item.setValue(NSNumber(integer: i), forKey: "i3")
|
||||
item.setValue(NSNumber(integer: i), forKey: "i4")
|
||||
item.setValue(NSNumber(integer: i), forKey: "i5")
|
||||
item.setValue(NSNumber(integer: i), forKey: "i6")
|
||||
item.setValue(NSNumber(integer: i), forKey: "i7")
|
||||
item.setValue(NSNumber(integer: i), forKey: "i8")
|
||||
item.setValue(NSNumber(integer: i), forKey: "i9")
|
||||
}
|
||||
try! moc.save()
|
||||
try! psc.removePersistentStore(store)
|
||||
try! NSFileManager.defaultManager().removeItemAtPath(databasePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
+18
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="9525" systemVersion="15B42" minimumToolsVersion="Xcode 7.0">
|
||||
<entity name="Item" representedClassName="ManagedItem" syncable="YES">
|
||||
<attribute name="i0" optional="YES" attributeType="Integer 64" syncable="YES"/>
|
||||
<attribute name="i1" optional="YES" attributeType="Integer 64" syncable="YES"/>
|
||||
<attribute name="i2" optional="YES" attributeType="Integer 64" syncable="YES"/>
|
||||
<attribute name="i3" optional="YES" attributeType="Integer 64" syncable="YES"/>
|
||||
<attribute name="i4" optional="YES" attributeType="Integer 64" syncable="YES"/>
|
||||
<attribute name="i5" optional="YES" attributeType="Integer 64" syncable="YES"/>
|
||||
<attribute name="i6" optional="YES" attributeType="Integer 64" syncable="YES"/>
|
||||
<attribute name="i7" optional="YES" attributeType="Integer 64" syncable="YES"/>
|
||||
<attribute name="i8" optional="YES" attributeType="Integer 64" syncable="YES"/>
|
||||
<attribute name="i9" optional="YES" attributeType="Integer 64" syncable="YES"/>
|
||||
</entity>
|
||||
<elements>
|
||||
<element name="Item" positionX="-63" positionY="-18" width="128" height="195"/>
|
||||
</elements>
|
||||
</model>
|
||||
@@ -169,6 +169,9 @@
|
||||
56DE7B281C41302500861EB8 /* FetchNamedValuesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B271C41302500861EB8 /* FetchNamedValuesTests.swift */; };
|
||||
56DE7B2A1C4130AF00861EB8 /* FetchPositionalValuesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B291C4130AF00861EB8 /* FetchPositionalValuesTests.swift */; };
|
||||
56DE7B2C1C41311900861EB8 /* FetchRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B2B1C41311900861EB8 /* FetchRecordTests.swift */; };
|
||||
56DE7B2F1C42B23B00861EB8 /* PerformanceModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 56DE7B2D1C42B23B00861EB8 /* PerformanceModel.xcdatamodeld */; };
|
||||
56DE7B351C42B37E00861EB8 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 56DE7B341C42B37E00861EB8 /* CoreData.framework */; };
|
||||
56DE7B371C42BBBB00861EB8 /* PerformanceCoreDataTests.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 56DE7B361C42BBBB00861EB8 /* PerformanceCoreDataTests.sqlite */; };
|
||||
56E5891F1BBA5D5400CC0140 /* NSURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E5891E1BBA5D5400CC0140 /* NSURL.swift */; };
|
||||
56E589201BBA5D5400CC0140 /* NSURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56E5891E1BBA5D5400CC0140 /* NSURL.swift */; };
|
||||
56E5D7D41B4D3FEE00430942 /* GRDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 56E5D7CA1B4D3FED00430942 /* GRDB.framework */; };
|
||||
@@ -402,6 +405,9 @@
|
||||
56DE7B271C41302500861EB8 /* FetchNamedValuesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchNamedValuesTests.swift; sourceTree = "<group>"; };
|
||||
56DE7B291C4130AF00861EB8 /* FetchPositionalValuesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchPositionalValuesTests.swift; sourceTree = "<group>"; };
|
||||
56DE7B2B1C41311900861EB8 /* FetchRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRecordTests.swift; sourceTree = "<group>"; };
|
||||
56DE7B2E1C42B23B00861EB8 /* PerformanceModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = PerformanceModel.xcdatamodel; sourceTree = "<group>"; };
|
||||
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 = "<group>"; };
|
||||
56E1524B1B43FD5B00EE27AA /* TODO.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = TODO.md; sourceTree = "<group>"; };
|
||||
56E5891E1BBA5D5400CC0140 /* NSURL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSURL.swift; sourceTree = "<group>"; };
|
||||
56E5D7CA1B4D3FED00430942 /* GRDB.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GRDB.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@@ -430,6 +436,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
56DE7B351C42B37E00861EB8 /* CoreData.framework in Frameworks */,
|
||||
560C98121C0E22D300BF8471 /* SQLite.framework in Frameworks */,
|
||||
560C98131C0E22D300BF8471 /* libsqlite3.tbd in Frameworks */,
|
||||
560C98141C0E22D300BF8471 /* GRDB.framework in Frameworks */,
|
||||
@@ -760,9 +767,8 @@
|
||||
56BB86101BA9886D001F9168 /* Performance */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56CA21FE1BB414FE009A04C5 /* SQLite.xcodeproj */,
|
||||
56BB86171BA988F2001F9168 /* fmdb */,
|
||||
56BB86111BA9886D001F9168 /* PerformanceTests.sqlite */,
|
||||
56DE7B361C42BBBB00861EB8 /* PerformanceCoreDataTests.sqlite */,
|
||||
56DE7B271C41302500861EB8 /* FetchNamedValuesTests.swift */,
|
||||
56DE7B291C4130AF00861EB8 /* FetchPositionalValuesTests.swift */,
|
||||
56DE7B2B1C41311900861EB8 /* FetchRecordTests.swift */,
|
||||
@@ -770,6 +776,9 @@
|
||||
56DE7B231C412F7E00861EB8 /* InsertPositionalValuesTests.swift */,
|
||||
56BB86121BA9886D001F9168 /* InsertRecordTests.swift */,
|
||||
56CA22211BB41565009A04C5 /* PerformanceTests.swift */,
|
||||
56CA21FE1BB414FE009A04C5 /* SQLite.xcodeproj */,
|
||||
56BB86171BA988F2001F9168 /* fmdb */,
|
||||
56DE7B2D1C42B23B00861EB8 /* PerformanceModel.xcdatamodeld */,
|
||||
);
|
||||
path = Performance;
|
||||
sourceTree = "<group>";
|
||||
@@ -871,6 +880,7 @@
|
||||
DC3773E919C8CBB3004FCF85 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56DE7B341C42B37E00861EB8 /* CoreData.framework */,
|
||||
56DBEC341C19A0020093A2EE /* CHANGELOG.md */,
|
||||
DC37744719C8F50B004FCF85 /* README.md */,
|
||||
56E1524B1B43FD5B00EE27AA /* TODO.md */,
|
||||
@@ -1186,6 +1196,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
560C98161C0E22D300BF8471 /* PerformanceTests.sqlite in Resources */,
|
||||
56DE7B371C42BBBB00861EB8 /* PerformanceCoreDataTests.sqlite in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1242,6 +1253,7 @@
|
||||
560C97F21C0E22D300BF8471 /* FMDatabasePool.m in Sources */,
|
||||
560C98241C0E23BB00BF8471 /* PerformanceTests.swift in Sources */,
|
||||
56DE7B261C412FDA00861EB8 /* InsertNamedValuesTests.swift in Sources */,
|
||||
56DE7B2F1C42B23B00861EB8 /* PerformanceModel.xcdatamodeld in Sources */,
|
||||
56DE7B2A1C4130AF00861EB8 /* FetchPositionalValuesTests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -1843,6 +1855,19 @@
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
|
||||
/* Begin XCVersionGroup section */
|
||||
56DE7B2D1C42B23B00861EB8 /* PerformanceModel.xcdatamodeld */ = {
|
||||
isa = XCVersionGroup;
|
||||
children = (
|
||||
56DE7B2E1C42B23B00861EB8 /* PerformanceModel.xcdatamodel */,
|
||||
);
|
||||
currentVersion = 56DE7B2E1C42B23B00861EB8 /* PerformanceModel.xcdatamodel */;
|
||||
path = PerformanceModel.xcdatamodeld;
|
||||
sourceTree = "<group>";
|
||||
versionGroupType = wrapper.xcdatamodel;
|
||||
};
|
||||
/* End XCVersionGroup section */
|
||||
};
|
||||
rootObject = DC3773EA19C8CBB3004FCF85 /* Project object */;
|
||||
}
|
||||
Reference in new issue
Block a user