Reputation: 11452
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
Option 2 : Creating new Object each time.
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!
Upvotes: 0
Views: 55
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