• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Program Efficiency
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Program Efficiency


  • Subject: Re: Program Efficiency
  • From: Peter Ammon <email@hidden>
  • Date: Wed, 06 Jun 2001 09:54:52 -0700

on 6/5/01 8:03 PM, Erik Thorteran at email@hidden wrote:

> Which of the following snippets of code will execute faster?
> Snippet one:
>
> [[NSDictionary dictionaryWithObjectsAndKeys:[[NSBundle mainBundle]
> bundlePath],@"path,etc, etc.] writeToFile:@"Wherever" atomically:YES]
>
> Snippet two:
>
> NSMutableDictionary *dict;
> dict=[[NSMutableDictionary alloc] init];
> [dict setObject:[[NSBundle mainBundle] bundlePath] forKey:@"path"];
> [dict setObject:continue forKey:@"irrelevant"];
> etc. etc.
> [dict writeToFile:@"Wherever" atomically:YES];
>
> Basically, is it more efficient to pack everything into one line, or
> multiple lines, or dies it not matter?
>
> Erik Thorteran

In general, immutable objects are faster than mutable ones and require less
memory, so I'd expect the first snippet to be slightly faster than the
second. If this is in a performance sensitive part of your code, then you
might get even better performance using the
dictionaryWithObjects:forKeys:count: method. Of course, you should profile,
since premature optimization is the root of all evil ;)

-Peter


References: 
 >Program Efficiency (From: Erik Thorteran <email@hidden>)

  • Prev by Date: Re: Threads in Apps
  • Next by Date: Re: Cocoa threading, objects by reference, and the keyword "oneway"
  • Previous by thread: Program Efficiency
  • Next by thread: NSComboBox/DataSource problems
  • Index(es):
    • Date
    • Thread