Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9126043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:56:44+00:00 2026-06-17T06:56:44+00:00

I am looking for the most efficient way to match an NSString against about

  • 0

I am looking for the most efficient way to match an NSString against about 200,000 other strings in the minimum amount of time. Basically I need to check, every once in a while, whether or not a word that is inputted is part of the English language.

What are the ways I could do this? I’ve heard about hashtables– is that the best way?


Here is the code I settled on:

EDIT:
benchmarks for dictionary initialization to memory:

NSDate *start = [NSDate date];

NSLog(@"initWords");

//temporary 
NSString *_filePath = [[NSBundle mainBundle] pathForResource:kFILE_NAME_FOR_DICTIONARY ofType:@"txt"];

NSLog(@"%@",_filePath);

NSString *_fileContents = [[NSString alloc] init];
NSData *_binary = [NSData dataWithContentsOfFile:_filePath];  

if (_binary) {  
    _fileContents = [[NSString alloc] initWithData:_binary encoding:NSUTF8StringEncoding];
}  else {

    NSLog(@"file parse error: did you forget to add the file? Please add file to:\n\n\n\n%@\n\n\n\n",[[NSBundle mainBundle] resourcePath]);
}

NSArray *_wordList = [_fileContents componentsSeparatedByString:kNEW_LINE_CHAR];

englishDictionary = [[NSMutableSet alloc] init];
[englishDictionary addObjectsFromArray:_wordList];

NSLog(@"Word count:\t%d",englishDictionary.count);
NSLog(@"Time to init dictionary:\t%f",[start timeIntervalSinceNow]*-1.);

iphone 5: 1.089725 (seconds)

ipad 1: 3.082753

iphone 4: 3.582853

Benchmark (time to test word if it is in the dictionary or not):

-(BOOL)checkWord:(NSString *)word{

    NSDate *start = [NSDate date];

    BOOL yesNoMaybeSo = [englishDictionary containsObject:word];

    NSLog(@"Time to check word:\t%f",[start timeIntervalSinceNow]*-1.);
    return yesNoMaybeSo;

}

iphone 5: 0.000021 (seconds)

ipad 1: 0.000037

iphone 4: 0.000043

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:56:45+00:00Added an answer on June 17, 2026 at 6:56 am

    The most efficient way is probably to use a NSSet to store all the words you want to compare against your string.

    Then you simply check whether your word belongs to the set like follows

    BOOL englishWord = [theEnglishSet containsObject:yourString];
    

    This will take constant time to perform.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for some general advice on the most efficient way to go about
I'm looking for the most efficient way to calculate the minimum number of bytes
I am looking for a most efficient way to re-use widgets with different selectors...
I am looking for the most efficient way to update a number of rows
I have a bipartite graph and I'm looking for the most efficient iterative way
Looking for the most efficient way to do the following: Details: 1 controller: Reports
I'm looking for the most efficient way to suck out a series of monthly
I'm looking for the most efficient way to add an element to a comma-separated
Hey, I'm looking for the most efficient way to maintain an object relative auto-incrementing
I'm looking for help/suggestions in finding the most efficient way to resize an image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.