(String[] args)
| 38 | public class Compete { |
| 39 | public static final int SIZE = 100000; |
| 40 | public static void |
| 41 | main(String[] args) throws Exception { |
| 42 | Thing2[] a = new Thing2[SIZE]; |
| 43 | for(int i = 0; i < SIZE; i++) |
| 44 | a[i] = new Thing2(); |
| 45 | Thing4[] b = new Thing4[SIZE]; |
| 46 | for(int i = 0; i < SIZE; i++) |
| 47 | b[i] = new Thing4(); |
| 48 | Timer timer = new Timer(); |
| 49 | try( |
| 50 | ByteArrayOutputStream buf = |
| 51 | new ByteArrayOutputStream(); |
| 52 | ObjectOutputStream oos = |
| 53 | new ObjectOutputStream(buf) |
| 54 | ) { |
| 55 | for(Thing2 a1 : a) { |
| 56 | oos.writeObject(a1); |
| 57 | } |
| 58 | // Now get copies: |
| 59 | try( |
| 60 | ObjectInputStream in = |
| 61 | new ObjectInputStream( |
| 62 | new ByteArrayInputStream( |
| 63 | buf.toByteArray())) |
| 64 | ) { |
| 65 | Thing2[] c = new Thing2[SIZE]; |
| 66 | for(int i = 0; i < SIZE; i++) |
| 67 | c[i] = (Thing2)in.readObject(); |
| 68 | } |
| 69 | } |
| 70 | System.out.println( |
| 71 | "Duplication via serialization: " + |
| 72 | timer.duration() + " Milliseconds"); |
| 73 | |
| 74 | // Now try cloning: |
| 75 | timer = new Timer(); |
| 76 | Thing4[] d = new Thing4[SIZE]; |
| 77 | for(int i = 0; i < SIZE; i++) |
| 78 | d[i] = b[i].clone(); |
| 79 | System.out.println( |
| 80 | "Duplication via cloning: " + |
| 81 | timer.duration() + " Milliseconds"); |
| 82 | } |
| 83 | } |
| 84 | /* Output: |
| 85 | Duplication via serialization: 385 Milliseconds |
nothing calls this directly
no test coverage detected