TeaCupApp
TeaCupApp

Reputation: 11452

Performance impact of these two method are same of different?

I have been developing iPhone application and just started adding CoreData for persistence. However I stumbled into one dilemma,

Context : I have Entity named Person, Person Entity has one Attribute name.

Task : Change name of Person object.(NSManagedObject)

Performance Test : Which option will be faster and better in matter of performance?

Option 1 : Assuming Object has been created once only

  1. Get object from CoreData
  2. Edit Object's name
  3. Save NSManagedObjectContext.

Option 2 : Creating new Object each time.

  1. Delete previously created object
  2. Create new Object
  3. Save NSManagedObjectContext.

NOTE : I have only one attribute! Name. Imagine I have game and user are being asked for their player name. I know there is will be not much difference in performance for a such a small task. But what later if I implement in something hardcore? So for defence which one is better?

Thanks for any kind of input!


My Thoughts : Both options should be similar in matter of performance. As fetching data and than updating and saving seems similar to delete recreate and save. I want someone to prove me wrong.

Upvotes: 0

Views: 55

Answers (1)

Duncan Babbage
Duncan Babbage

Reputation: 20187

Option 1 is better because Option 2 is nutty.

I haven't tested the performance, but it seems highly unlikely that Option 2 would be faster, since there is overhead associated with creating an object. But even if Option 2 was marginally faster it doesn't make logical sense as a process so it isn't a great way to structure your code. If it continues to be the same Person you're representing, then represent them with the same object. Anything else is just asking for headaches down the track in unexpected ways, since you're starting off with an odd arrangement. :)

Upvotes: 1

Related Questions