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];
jscs
  • 63,694
  • 13
  • 151
  • 195
Cody C
  • 3,087
  • 4
  • 24
  • 32

1 Answers1

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.

bbum
  • 162,346
  • 23
  • 271
  • 359
  • 6
    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 :) – Ted Avery Jan 23 '14 at 04:28