Searching through text - Speed issue

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I was searching a list of 100 key words in a 1 million line text file. I used
two methods of looping the search:
1. I loop through all lines in the text file for each key word
2. I loop through all key words for each line in the text file

Both ways search through 100 times 1 million lines. How come after many
tests, the second method is about 30% faster than the first?
 
I would chance at guess at this:

1) You are hitting the disk 100 times to re-read the text file for each
search (or, if you have read the entire text file into one humongous array,
you are still hitting the disk multiple times due to the large array being
swapped out in a system page file.)

2) You are reading the file once from beginning to end while checking
against a very small array of search items entirely in local memory.

That's about the best I can guess about system stuff.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top