package com.edwin.common;import java.lang.reflect.Method;import java.util.List;public class RunTime { public static long invokeStaticMethod(String clsName, String methodName, Object[] args) throws Exception { long start = System.nanoTime(); try { Class c = Class.forName(clsName); Class[] argsClass = new Class[] {List.class}; Method method = c.getMethod(methodName, argsClass); method.invoke(c, args); } catch (Exception e) { e.printStackTrace(); } long end = System.nanoTime(); return end - start; }}
package com.edwin.common;import java.lang.reflect.Method;import java.util.ArrayList;import java.util.List; import org.apache.commons.collections.CollectionUtils;import org.apache.commons.collections.Transformer;public class Test { /** * @param args */ public static ListStringToIntegerLst(List inList){ List iList =new ArrayList (inList.size()); try{ for(int i=0,j=inList.size();i CollStringToIntegerLst(List inList){ List iList =new ArrayList (inList.size()); CollectionUtils.collect(inList, new Transformer(){ public java.lang.Object transform(java.lang.Object input){ return new Integer((String)input); } } ,iList ); return iList; } public static void main(String[] args) { List sList = new ArrayList (); for (int i=0;i<1000;i++) { sList.add(String.valueOf(i)); } Object[] param=new Object[]{sList}; try { long runTime=RunTime.invokeStaticMethod("com.edwin.common.Test", "StringToIntegerLst", param); System.out.println("采用顺序转化方法执行时间"+runTime); long runTimeByColl=RunTime.invokeStaticMethod("com.edwin.common.Test", "CollStringToIntegerLst", param); System.out.println("采用org.apache.commons.collections.CollectionUtils执行时间"+runTimeByColl); System.out.println("微秒相差(runTimeByColl-runTime)=" +String.valueOf(runTimeByColl-runTime)); } catch (Exception e) { e.printStackTrace(); } }}