• 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: Reading in dictionary from txt file: options for speed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading in dictionary from txt file: options for speed


  • Subject: Re: Reading in dictionary from txt file: options for speed
  • From: Marcel Weiher <email@hidden>
  • Date: Thu, 16 Apr 2009 10:43:39 -0700

Hi Wagner,

we have rather impressive hardware these days, and Objective-C can access all that power if you let it. The 0.007 time for the simulator you got sounds about right, my 0.043 was a typo, I was missing a leading zero (fast MacPro). Incidentally, the - [start timeIntervalSinceNow] you used in your code is a really clever trick for getting elapsed time, it took me a while to figure out that it was not a bug :-)

Cheers,

Marcel


On Apr 15, 2009, at 19:01 , WT wrote:

that's quite impressive. On the simulator on my machine, it took 0.007 seconds, consistently. Learned something new with your message.

On Apr 16, 2009, at 12:35 AM, Marcel Weiher wrote:

I would do the following:

1. map the file into memory using -[NSData dataWithContentsOfMappedFile:] (or mmap() if you really want to)
2. Do not convert to individual objects for the words
3. get the pointer to the raw bytes
4. search using a little bit of plain old C (assuming you're OK with encodings)



Memory mapping will be essentially instantaneous, with the I/O performed on-demand when its actually needed (or you can pre-heat the data, for example in a background thread). More importantly, you will be doing good things for memory consumption, because the mapped memory can be released to the OS without having to kill your app in low-memory situations (without paging it out on Mac OS X, but the iPhone doesn't page memory out).


I added an implementation of this approach to the testing program provided by Wagner (thanks!) and it loads + counts the words in 0.084 seconds on the device. That's anywhere from around 50 - 100 times faster than the other methods implemented in DictTest (plist / xml / txt ). On the simulator, it runs in 0.043 seconds, so around 30-40 times faster than the other methods.

Download can be found here:

	http://www.metaobject.com/downloads/Objective-C/DictTest.tgz

You mentioned that you were OK with search performance, so I won't go into that.

Cheers,

Marcel

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Reading in dictionary from txt file: options for speed
      • From: WT <email@hidden>
References: 
 >Reading in dictionary from txt file: options for speed (From: Miles <email@hidden>)
 >Re: Reading in dictionary from txt file: options for speed (From: Marcel Weiher <email@hidden>)
 >Re: Reading in dictionary from txt file: options for speed (From: WT <email@hidden>)

  • Prev by Date: Re: Reading in dictionary from txt file: options for speed
  • Next by Date: Re: Importing Word doc in Carbon app via Cocoa
  • Previous by thread: Re: Reading in dictionary from txt file: options for speed
  • Next by thread: Re: Reading in dictionary from txt file: options for speed
  • Index(es):
    • Date
    • Thread