1 21 package com.db4o.test.performance; 22 23 import java.io.*; 24 25 import com.db4o.io.*; 26 27 31 public class RunIOBench { 32 public static void main(String [] args) throws IOException { 33 34 RandomAccessFile recordedIn = new RandomAccessFile(Util.BENCHFILE+".1", "rw"); 35 new File(Util.DBFILE).delete(); 36 IoAdapter testadapt = new RandomAccessFileAdapter().open(Util.DBFILE, 37 false, 1024); 38 39 long bench = benchmark(recordedIn, testadapt); 44 System.out.println("tested IOAdapter: [" 45 + testadapt.getClass().getName() + "]\nspeed: " + bench); 46 } 47 48 public static long benchmark(RandomAccessFile recordedIn, IoAdapter adapter) 49 throws IOException { 50 byte[] defaultData = new byte[1000]; 51 long start = System.currentTimeMillis(); 52 int runs = 0; 53 try { 54 while (true) { 55 runs++; 56 char type = recordedIn.readChar(); 57 if (type == 'q') { 58 break; 59 } 60 if (type == 'f') { 61 adapter.sync(); 62 continue; 63 } 64 long pos = recordedIn.readLong(); 65 int length = recordedIn.readInt(); 66 adapter.seek(pos); 67 byte[] data = (length <= defaultData.length ? defaultData 68 : new byte[length]); 69 switch (type) { 70 case 'r': 71 adapter.read(data, length); 72 break; 73 case 'w': 74 adapter.write(data, length); 75 break; 76 default: 77 throw new IllegalArgumentException ("Unknown access type: " 78 + type); 79 } 80 } 81 } finally { 82 recordedIn.close(); 83 adapter.close(); 84 } 85 return System.currentTimeMillis() - start; 87 } 88 } | Popular Tags |