package com.mindprod.example;
import com.mindprod.common18.EIO;
import java.io.UnsupportedEncodingException;
import java.util.zip.CRC32;
import static java.lang.System.*;
/**
* 32-bit Sun CRC cyclic redundancy checks.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2009-01-01 initial version
* @since 2009-01-01
*/
public final class TestSunCRC32
{
/**
* Calc CRC-32 with Sun method
*
* @param ba byte array to compute CRC on
*
* @return 32-bit CRC, signed
*/
private static int sunCRC32( byte[] ba )
{
final CRC32 crc = new CRC32();
crc.update( ba );
return ( int ) crc.getValue();
}
/**
* Test harness
*
* @param args not used
*
* @throws java.io.UnsupportedEncodingException in case UTF-8 support is missing.
*/
public static void main( String[] args ) throws UnsupportedEncodingException
{
final String s = "The quick brown fox jumped over the lazy dog's back; sample url: http://mindprod.com/jgloss/digest.html";
final byte[] theTextToDigestAsBytes = s.getBytes( EIO.UTF8 );
out.println( sunCRC32( theTextToDigestAsBytes ) );
long start = System.nanoTime();
for ( int i = 0; i < 100_000100_000; i++ )
{
sunCRC32( theTextToDigestAsBytes );
}
long stop = System.nanoTime();
out.println( ( stop - start ) / 1_000_0001_000_000L + " seconds to compute 100,000 sunCRC32 hashes" );
}
}