PageRenderTime 21ms CodeModel.GetById 10ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/ictclas4j/src/org/ictclas4j/test/UtilityTest.java

http://ictclas4j.googlecode.com/
Java | 105 lines | 66 code | 19 blank | 20 comment | 11 complexity | 970507d48ba85e0a2a6acb4f08fa04dd MD5 | raw file
  1package org.ictclas4j.test;
  2
  3import java.util.ArrayList;
  4import java.util.HashMap;
  5
  6import org.apache.log4j.Logger;
  7import org.apache.log4j.PropertyConfigurator;
  8import org.ictclas4j.run.Config;
  9import org.ictclas4j.util.Utility;
 10
 11import com.gftech.util.GFString;
 12
 13//test1
 14//test2
 15public class UtilityTest {
 16
 17	static Logger logger = Logger.getLogger(UtilityTest.class);
 18
 19	public static void main(String[] args) {
 20
 21		PropertyConfigurator.configure(Config.LOG4J_CONF);
 22		test3();
 23	}
 24
 25	private static void test1() {
 26		System.out.println(Utility.GBK_ID("?"));
 27
 28		byte[] bs = new byte[2];
 29		// for(int i=0xa1;i<0xb0;i++)
 30		// for(int j=0xa1;j<0xFF;j++){
 31		// bs[0]=(byte)i;
 32		// bs[1]=(byte)j;
 33		// System.out.println(i+","+j+":"+new String(bs));
 34		// }
 35		//			
 36		ArrayList<String> list = new ArrayList<String>();
 37		for (int i = 21998; i < 22034; i++) {
 38			String w = Utility.getGBKWord(i);
 39			String str = i + "," + GFString.int2hex(i, 4) + ":" + w;
 40			list.add(str);
 41
 42			System.out.println(str);
 43			if (w != null && Utility.GBK_ID(w) != i) {
 44				System.err.println("\nerr:" + w + "," + Utility.GBK_ID(w));
 45				// break;
 46			}
 47
 48		}
 49		//			
 50		// try {
 51		// GFFile.writeTxtFile("test\\gbk_test.txt",list,false);
 52		// } catch (IOException e) {
 53		// e.printStackTrace();
 54		// }
 55		//		
 56	}
 57
 58	// test GBK_ID() profile
 59	public static void test2() {
 60		String s = "??????????????c?????????D?????????6?1??3??????????9????????????????????????????????????????????????????????????? ???????????????????????? ???? ?????????a?????????????????????????????";
 61		int count = 0;
 62		HashMap<String, Integer> idMap = new HashMap<String, Integer>();
 63		for (int i = 0; i < Utility.GBK_NUM_EXT; i++) {
 64			idMap.put(Utility.getGBKWord(i), i);
 65		}
 66		String[] ss = new String[s.length()];
 67		for (int j = 0; j < s.length(); j++) {
 68			ss[j] = s.substring(j, j + 1);
 69		}
 70		long start = System.currentTimeMillis();
 71		for (int i = 0; i < 100000; i++) {
 72			for (String s0 : ss) {
 73				count++;
 74				// idMap.get(s0);
 75				Utility.GBK_ID(s0);
 76			}
 77		}
 78
 79		long end = System.currentTimeMillis();
 80		long spend = end - start;
 81		System.out.println("total time:" + spend + ",avg time:" + ((double) spend / count));
 82
 83	}
 84
 85	// test substring's time of String and StringBuffer
 86	public static void test3() {
 87		int count = 0;
 88		String s = "??????????????c?????????D?????????6?1??3??????????9????????????????????????????????????????????????????????????? ???????????????????????? ???? ?????????a?????????????????????????????";
 89		StringBuffer sb=new StringBuffer(s);
 90		
 91		long start = System.currentTimeMillis();
 92		for (int i = 0; i < 1000000; i++) {
 93			for (int j = 0; j < s.length(); j++) {
 94			  sb.substring(j, j + 1);
 95			  count++;
 96			}
 97		}
 98		
 99		long end = System.currentTimeMillis();
100		long spend = end - start;
101		System.out.println("total time:" + spend + ",avg time:" + ((double) spend / count));
102
103	}
104
105}