°øÀ¯ÀÚ·á HOME > ÀÚ·á½Ç > °øÀ¯ÀÚ·á
 
[ºòµ¥ÀÌÅͺм®·Ð]WordCounts_stoppingwords_performance.java
°ü¸®ÀÚ 15-04-01 10:16 962
   WordCounts_stoppingwords_performance.java (2.7K) [58] DATE : 2015-04-01 13:22:56
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.IllegalStateException;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class WordCounts_stoppingwords_performance
{
 public static String[] readStoppingWord()
 {
      String it = "";
   int count = 0;
   String word[] = new String[100];
      try
      {
         Scanner input = new Scanner( new File( "stoppingwords.txt" ) );
  while (input.hasNext() )
  {
   word[count] = input.next();
   count++;
  }
      } // end try
      catch ( FileNotFoundException fileNotFoundException )
      {
         System.err.println( "Error opening file." );
         System.exit( 1 );
      } // end catch
 return word;
 }
 public static void main(String[] args)
 {
  int loop = Integer.parseInt(args[0]);
  double accumulateTime = 0.0;
  double square_accumulateTime = 0.0;
     for (int i=0; i<=loop; i++)
  {
   // ½ÃÀÛ ½Ã°¢
   double startime = System.currentTimeMillis();
    String stoppingword[] = new String[100];
       String it = "";
    int count = 0;
    int wcount[] = new int[100];
       try
    {
    Scanner input = new Scanner( new File( "cnn.txt" ) );
    WordCounts_stoppingwords ws = new WordCounts_stoppingwords();
    stoppingword = ws.readStoppingWord();
   while (input.hasNext() )
   {
    it = input.next();
    int k = 0;
    boolean signal = true;
    while (stoppingword[k]!=null)
    {
     if (it.compareTo(stoppingword[k])==0) signal = false;
     k++;
    }
    if (signal == true)
    {
     count++;
//     System.out.println("["+count+"] "+it);
    }
   }
   System.out.println("Total number of words = "+count);

    } // end try
       catch ( FileNotFoundException fileNotFoundException )
    {
    System.err.println( "Error opening file." );
          System.exit( 1 );
    } // end catch
  // ³¡ ½Ã°¢
  double endtime = System.currentTimeMillis();
  double elapsedtime = endtime - startime;
  accumulateTime += elapsedtime;
  square_accumulateTime += elapsedtime*elapsedtime;
  System.out.println("elapsed time = "+elapsedtime+" msec");
  }
  System.out.println("Mean elapsed time = "+accumulateTime/loop+" msec");
  System.out.println("Std of elapsed time = "+Math.sqrt((square_accumulateTime-2*accumulateTime*(accumulateTime/loop)+loop*Math.pow(accumulateTime/loop,2))/loop));
System.out.println(square_accumulateTime-2*accumulateTime*(accumulateTime/loop)+loop*Math.pow(accumulateTime/loop,2));

 }
}