1 package org.sapia.ubik.rmi.server.perf; 2 3 import org.sapia.ubik.net.*; 4 import org.sapia.ubik.rmi.server.*; 5 6 import java.io.*; 7 8 import java.util.*; 9 10 11 19 public class SerPerf { 20 public static void main(String [] args) { 21 try { 22 List objects = new ArrayList(); 23 24 for (int k = 0; k < 2; k++) { 25 for (int i = 0; i < 2000; i++) { 26 if (k == 0) { 27 objects.add(newRemoteRef(i)); 28 } else { 29 objects.add(newString(i)); 30 } 31 } 32 33 if (k == 0) { 34 System.out.println(" ==== results for remote refs ===="); 35 } else { 36 System.out.println(" ==== results for strings ===="); 37 } 38 39 long start = System.currentTimeMillis(); 40 InputStream is = serialize(objects.toArray()); 41 long delay = System.currentTimeMillis() - start; 42 System.out.println("serialization delay: " + delay); 43 start = System.currentTimeMillis(); 44 deserialize(is); 45 delay = System.currentTimeMillis() - start; 46 System.out.println("deserialization delay: " + delay); 47 objects.clear(); 48 } 49 } catch (Throwable t) { 50 t.printStackTrace(); 51 } 52 } 53 54 public static RemoteRef newRemoteRef(int i) { 55 return new RemoteRefEx(new OID(i), new TCPAddress("localhost", 8080)); 56 } 57 58 public static String newString(int i) { 59 return "" + i; 60 } 61 62 public static InputStream serialize(Object [] objects) 63 throws Throwable { 64 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 65 ObjectOutputStream out = new ObjectOutputStream(bos); 66 out.writeObject(objects); 67 out.flush(); 68 out.close(); 69 70 return new ByteArrayInputStream(bos.toByteArray()); 71 } 72 73 public static Object [] deserialize(InputStream is) throws Throwable { 74 ObjectInputStream ois = new ObjectInputStream(is); 75 76 return (Object []) ois.readObject(); 77 } 78 } 79 | Popular Tags |