Skip to content

Instantly share code, notes, and snippets.

@kastiglione
Created February 21, 2013 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kastiglione/5006618 to your computer and use it in GitHub Desktop.
Save kastiglione/5006618 to your computer and use it in GitHub Desktop.
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