import library.io.*; import java.kernel.*; public class SKMemoryTest{ static final int MAX_FILE_NUM = 1019; static Runtime rt = Runtime.getRuntime(); static int filenum = 0; // static long free1, free2; static long start, end; static RandomAccessFile farray[]; static int round = 1; static long open_overhead = 0; //static long mem_overhead = 0; public static void main(String[] args){ President.setCurrentCell(new SKMemoryTest()); President.setSecurityManager(true); if(args.length > 0) filenum = Integer.parseInt(args[0]); System.out.println("input filenum = " + filenum); if (filenum <= 0) filenum = MAX_FILE_NUM; File f = new File("MemoryTest.dat"); for(int j = 0 ; j < round; j++){ long start, end; farray= new RandomAccessFile[filenum]; // free1 = rt.freeMemory(); start = System.currentTimeMillis(); test(f); end = System.currentTimeMillis(); //free2 = rt.freeMemory(); open_overhead +=(end-start); //mem_overhead +=(free1-free2); } System.out.println("File number :" + filenum); System.out.println("Time overhead :" + open_overhead/round + " millseconds"); // System.out.println("Memory overhead :" + mem_overhead/round + "bytes"); clear(); } static void test(File f){ int i = 0; while(i < filenum){ try{ farray[i] = new RandomAccessFile(f, "rw"); }catch(Exception e){e.printStackTrace();} i++; } } static void clear(){ int i = 0; while(i < farray.length){ try{ ((RandomAccessFile)farray[i]).close(); }catch(Exception e){e.printStackTrace();} farray[i] = null; i++; } farray = null; } }