Is literal creation of an NSMutableDictionary less efficient than the class helper method?
Asked Answered
R

1

12

Is it appreciably more efficient to create an NSMutableDictionary using a constructor

[NSMutableDictionary dictionaryWithObjectsAndKeys:@"object1", @"key1", @2, @"key2", nil];

than taking the mutable copy of a literal

[@{@"key1":@"object1", @"key2":@2} mutableCopy];
Residence answered 14/9, 2012 at 14:43 Comment(1)
Instruments.app or it didn't happen.Outwit
L
14

As Jeremy said; measure, measure, measure.... then optimize if you have a real problem.

Without looking at the source, I can think of possible reasons why either might be faster and that answer may change depending on # of entries.

The real question, though, is why do you have an app architecture where it matters? It is quite rare to have an application that is creating so many mutable dictionaries (or dictionaries so large) that it is a performance issue.

Loads answered 14/9, 2012 at 16:10 Comment(1)
There are a lot of best practices out there in software development that don't usually "matter", but if we know the best way to do it from the start, we can prevent errors in cases where it DOES matter :)Trothplight

© 2022 - 2024 — McMap. All rights reserved.