vendredi 29 janvier 2016

How to do Random word search to check the time taken?

I have a method to search for a word from multiple files. Now I am trying to do random word search to calcualte the efficiency of different methods. But I dono where to start. Can some one please advice me how to do this.

My current code :

private static HashMap search(String stringToLookFor) throws IOException {

HashMap<String, Integer> result = new HashMap<String, Integer>();
for (File file : list) {
  String fileName = file.getName();
  // System.out.println(fileName);
  FileInputStream fstream = new FileInputStream(file);
  BufferedReader in = new BufferedReader(new InputStreamReader(fstream));
  String readLine = "";
  int count = 0;
  while ((readLine = in.readLine()) != null) {
    String[] words = readLine.split("\\W");
    for (String text : words) {
      if (text.equalsIgnoreCase(stringToLookFor)) {
        count++;
      }
    }
  }
  if (count != 0) {
    result.put(fileName, count);
  }

  in.close();
}

return result;

}

How to get random words(like 3 M words) to search in the given files ?




Aucun commentaire:

Enregistrer un commentaire