If I do:
foos[i] = [[Foo alloc] init];
foos[i].prop = @"bar";
[foos[i] baz];
… Is that less efficient than:
Foo *foo = [[Foo alloc] init];
foo.prop = @"bar";
[foo baz];
foos[i] = foo;
or are they equivalent?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If your array is a simple a C array (
Foo * array[11];), then it will not have significant performance impact.If your array is an
NSMutableArray(or another subscriptable NS-type), then it will have to call the method’s implementation repeatedly (which uses short circuited dispatch), so that will introduce some overhead. Although some would consider it a micro-optimization. In this case, the compiler cannot know what the implementation returns, so it cannot omit the calls.Here are basic wall clock time results:
and the program (which you can perform the obvious ARC changes to to test ARC):