test/java/util/zip/TimeChecksum.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Sdiff test/java/util/zip

test/java/util/zip/TimeChecksum.java

Print this page


   1 /*
   2  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 103             throw new RuntimeException();
 104         }
 105         buf.position(pos);
 106     }
 107 
 108     public static void main(String[] args) {
 109         int len     = 1024 * 32;
 110         int iters   = 1;
 111         if (args.length != 0 && "-benchmark".equals(args[0]))
 112             iters = 100000;
 113         Adler32 adler32 = new Adler32();
 114         CRC32 crc32 = new CRC32();
 115         Random rdm = new Random();
 116         byte[] data = new byte[len];
 117         new Random().nextBytes(data);
 118         ByteBuffer buf;
 119 
 120         System.out.println("---------- Adler32 ----------");
 121         System.out.print("Warmup...");
 122         time(adler32, data, iters, len);

 123         time(adler32, ByteBuffer.wrap(data), iters);
 124         buf = ByteBuffer.allocateDirect(len);
 125         buf.put(data, 0, len);
 126         buf.flip();
 127         time(adler32, buf, iters);
 128         System.out.println("\n");
 129 
 130         System.out.println("Length    byte[](ns/len)  ByteBuffer(direct)   ByteBuffer");
 131         for (int testlen = 1; testlen < data.length; testlen <<= 1) {
 132             System.out.print(testlen + "\t");
 133             long baT = time(adler32, data, iters, testlen);
 134             long baV = adler32.getValue();
 135             System.out.print("\t");
 136 
 137             buf = ByteBuffer.allocateDirect(testlen);
 138             buf.put(data, 0, testlen);
 139             buf.flip();
 140             long bbdT = time(adler32, buf, iters);
 141             long bbdV = adler32.getValue();
 142             if (baV != bbdV) {


 145             }
 146             System.out.printf(" (%.2f)", (float)bbdT/baT);
 147             testPosLimit(adler32, buf);
 148 
 149             buf = ByteBuffer.allocate(testlen);
 150             buf.put(data, 0, testlen);
 151             buf.flip();
 152             long bbT = time(adler32, buf, iters);
 153             long bbV = adler32.getValue();
 154             if (baV != bbV) {
 155                 System.out.printf("%nFAILED: baV=%x,bbV=%x%n", baV, bbV);
 156                 throw new RuntimeException();
 157             }
 158             testPosLimit(adler32, buf);
 159             System.out.printf(" (%.2f)     checksum=%x%n", (float)bbT/baT, bbV);
 160         }
 161 
 162         System.out.println("\n---------- CRC32 ----------");
 163         System.out.print("Warmup...");
 164         time(crc32, data, iters, len);

 165         time(crc32, ByteBuffer.wrap(data), iters);
 166         buf = ByteBuffer.allocateDirect(len);
 167         buf.put(data, 0, len);
 168         buf.flip();
 169         time(crc32, buf, iters);
 170         System.out.println("\n");
 171 
 172 
 173         System.out.println("Length    byte[](ns/len)  ByteBuffer(direct)   ByteBuffer");
 174         for (int testlen = 1; testlen < data.length; testlen <<= 1) {
 175             System.out.print(testlen + "\t");
 176             long baT = time(crc32, data, iters, testlen);
 177             long baV = crc32.getValue();
 178             System.out.print("\t");
 179 
 180             buf = ByteBuffer.allocateDirect(testlen);
 181             buf.put(data, 0,  testlen);
 182             buf.flip();
 183             long bbdT = time(crc32, buf, iters);
 184             long bbdV = crc32.getValue();


   1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 103             throw new RuntimeException();
 104         }
 105         buf.position(pos);
 106     }
 107 
 108     public static void main(String[] args) {
 109         int len     = 1024 * 32;
 110         int iters   = 1;
 111         if (args.length != 0 && "-benchmark".equals(args[0]))
 112             iters = 100000;
 113         Adler32 adler32 = new Adler32();
 114         CRC32 crc32 = new CRC32();
 115         Random rdm = new Random();
 116         byte[] data = new byte[len];
 117         new Random().nextBytes(data);
 118         ByteBuffer buf;
 119 
 120         System.out.println("---------- Adler32 ----------");
 121         System.out.print("Warmup...");
 122         time(adler32, data, iters, len);
 123         time(adler32, data, 2*iters, 16); // warmup short case, too
 124         time(adler32, ByteBuffer.wrap(data), iters);
 125         buf = ByteBuffer.allocateDirect(len);
 126         buf.put(data, 0, len);
 127         buf.flip();
 128         time(adler32, buf, iters);
 129         System.out.println("\n");
 130 
 131         System.out.println("Length    byte[](ns/len)  ByteBuffer(direct)   ByteBuffer");
 132         for (int testlen = 1; testlen < data.length; testlen <<= 1) {
 133             System.out.print(testlen + "\t");
 134             long baT = time(adler32, data, iters, testlen);
 135             long baV = adler32.getValue();
 136             System.out.print("\t");
 137 
 138             buf = ByteBuffer.allocateDirect(testlen);
 139             buf.put(data, 0, testlen);
 140             buf.flip();
 141             long bbdT = time(adler32, buf, iters);
 142             long bbdV = adler32.getValue();
 143             if (baV != bbdV) {


 146             }
 147             System.out.printf(" (%.2f)", (float)bbdT/baT);
 148             testPosLimit(adler32, buf);
 149 
 150             buf = ByteBuffer.allocate(testlen);
 151             buf.put(data, 0, testlen);
 152             buf.flip();
 153             long bbT = time(adler32, buf, iters);
 154             long bbV = adler32.getValue();
 155             if (baV != bbV) {
 156                 System.out.printf("%nFAILED: baV=%x,bbV=%x%n", baV, bbV);
 157                 throw new RuntimeException();
 158             }
 159             testPosLimit(adler32, buf);
 160             System.out.printf(" (%.2f)     checksum=%x%n", (float)bbT/baT, bbV);
 161         }
 162 
 163         System.out.println("\n---------- CRC32 ----------");
 164         System.out.print("Warmup...");
 165         time(crc32, data, iters, len);
 166         time(crc32, data, 2*iters, 16); // warmup short case, too
 167         time(crc32, ByteBuffer.wrap(data), iters);
 168         buf = ByteBuffer.allocateDirect(len);
 169         buf.put(data, 0, len);
 170         buf.flip();
 171         time(crc32, buf, iters);
 172         System.out.println("\n");
 173 
 174 
 175         System.out.println("Length    byte[](ns/len)  ByteBuffer(direct)   ByteBuffer");
 176         for (int testlen = 1; testlen < data.length; testlen <<= 1) {
 177             System.out.print(testlen + "\t");
 178             long baT = time(crc32, data, iters, testlen);
 179             long baV = crc32.getValue();
 180             System.out.print("\t");
 181 
 182             buf = ByteBuffer.allocateDirect(testlen);
 183             buf.put(data, 0,  testlen);
 184             buf.flip();
 185             long bbdT = time(crc32, buf, iters);
 186             long bbdV = crc32.getValue();


test/java/util/zip/TimeChecksum.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File