IPhone: How long does it take to search?

Here is a very direct question: How long does it take to find an array of 200-300 strings locally? How about remotely?

0


a source to share


4 answers


Search? In what sense?

If you just use:

[myStringArray containsObject:searchString];

      

then 200-300 lines can be searched within a few microseconds.

If you are looking for:



BOOL found = NO
for (NSString *string in myStringArray)
{
    if ([string rangeOfString:searchString].location != NSNotFound)
    {
        found = YES;
         break;
    }
}

      

Then it almost entirely depends on the length of each line, but for lines less than a few dozen characters, it is about the same as the previous search speed.

Remote search is completely different - but it is a huge waste of time for such an operation. It is completely based on network latency. With an average ping of 250ms, the average time for a remote operation is about half a second or more, because it takes a long time to generate network packets, send over the network, wait for the remote server to receive, wait for the remote server to process, wait for a response, and parse the response.

If this question was round, ask: do I just need to iterate over all 30 lines and search locally - then: yes, search locally. Generally: Local searches are faster until the time taken to download all of the results becomes a burden (compared to 3G, I usually consider 50KB as the maximum for fast transparent downloads).

+1


a source


If you are searching alphabetic strings and the search time is prohibitive, you can try converting a list of strings in a DAWG (directed acyclic word graph, easy for Google). I did this for a very long list (about 170,000 words) and got an improvement rate of 18,000.



jrdoner

+2


a source


microseconds. its swiftly fast. I was surprised when I found out about this: p

+1


a source


This applies to local string searches.

I have implemented a Trie data structure to index rows for fast autocomplete. http://en.wikipedia.org/wiki/Trie

0


a source







All Articles