Created
February 21, 2013 17:43
-
-
Save kastiglione/5006618 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppDelegate | |
def application(application, didFinishLaunchingWithOptions:launchOptions) | |
a = NSEntityDescription.new | |
a.name = 'A' | |
b = NSEntityDescription.new | |
b.name = 'B' | |
bs = NSRelationshipDescription.new | |
bs.name = 'bs' | |
bs.destinationEntity = b | |
bs.ordered = true | |
a.properties = [bs] | |
model = NSManagedObjectModel.new | |
model.entities = [a, b] | |
store = NSPersistentStoreCoordinator.alloc.initWithManagedObjectModel(model) | |
storeURL = NSFileManager.defaultManager.URLsForDirectory(NSDocumentDirectory, inDomains:NSUserDomainMask).first | |
storeURL = storeURL.URLByAppendingPathComponent('data.sqlite') | |
store.addPersistentStoreWithType(NSSQLiteStoreType, configuration:nil, URL:storeURL, options:nil, error:nil) | |
context = NSManagedObjectContext.new | |
context.persistentStoreCoordinator = store | |
context.undoManager = nil | |
start = NSDate.date | |
theA = NSManagedObject.alloc.initWithEntity(a, insertIntoManagedObjectContext:context) | |
muchBs = 5000.times.map do | |
NSManagedObject.alloc.initWithEntity(b, insertIntoManagedObjectContext:context) | |
end | |
context.save(nil) | |
createTime = '%.2fs' % -start.timeIntervalSinceNow | |
start = NSDate.date | |
theA.setBs(NSOrderedSet.orderedSetWithArray(muchBs)) | |
context.save(nil) | |
associateTime = '%.2fs' % -start.timeIntervalSinceNow | |
UIAlertView.alloc.initWithTitle('Results', message:"Create: #{createTime}, Associate: #{associateTime}", delegate:nil, cancelButtonTitle:'OK', otherButtonTitles:nil).show | |
true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment