• 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
NSSet Inefficiency
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSSet Inefficiency


  • Subject: NSSet Inefficiency
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Sat, 23 Mar 2002 15:11:44 +0100

I have an app which creates about 2 million objects, halve of these are different. And I want to keep only these different objects.

1. strategy: NSMutableSet
set = [ NSMutableSet initWithCapacity: 0]
for( ii = 1 to 2000000)
create newThing[ii]
oldThing = [ set member: newThing ]
if ( oldThing == nil )
[ set addObject: newThing ]
else
[ newThing release ]
use oldThing

This seemed somehow slow, so I tried:

2. strategy: SortedArray
I added a Category to MutableArray with insertObject: usingSelector:

set = [ NSMutableArray initWithCapacity: 0]
for( ii = 1 to 2000000)
create newThing[ii]
oldThing = [ set insertObject: newThing usingSelector: some method ]
if ( oldThing == nil )
// newThing was really new and has been inserted
else
[ newThing release ]
use oldThing

This turned out to be 10 times faster than the first strategy: 2 minutes instead of 20.

Now two questions:
1. Is NSSet really that inefficient, of did I commit any grave mistakes?
2. Is there any efficient open-source implementation of a sorted array (maybe using B-trees) around?

Gerriet
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSSet Inefficiency
      • From: Nat! <email@hidden>
    • Re: NSSet Inefficiency
      • From: Ondra Cada <email@hidden>
  • Prev by Date: Re: CADO: Cocoa Application Developers Organization?
  • Next by Date: Re(2): CADO: Cocoa Application Developers Organization?
  • Previous by thread: Re: Cocoa and UNIX txt files ??
  • Next by thread: Re: NSSet Inefficiency
  • Index(es):
    • Date
    • Thread