From: Thomas M. <hyp...@gm...> - 2005-03-24 10:35:02
|
Hi, I have made some speed improvements for your Adler32 implementation. In my test, the old code takes 1731 ms, my code takes 1061 ms. public void update(byte[] buffer, int off, int len) { int s1 = checksum & 0xffff; int s2 = checksum >>> 16; while (off < len) { int max = Math.min(off + DEFER, off + len); while (off < max) { s1 = (buffer[off++] & 0xff) + s1; s2 += s1; } s1 %= BASE; s2 %= BASE; } checksum = (s2 << 16) | s1; } The important changes are: - only increment one value (off++) in the main loop instead of (off++) and (n--) - s1=...+s1 is a lot faster than s1=s1+... for some unknown reason (maybe the processor pipeline?) DEFER is a new constant: private final static int DEFER = 3850; I calculated this value like this: static { int i=0, a=BASE, b=a; for(;b>0;i++) b += (a += 255); System.out.println("max defer = " + (i-1)); } I hope this helps, Thomas (developer of the original Hypersonic SQL) -- Handyrechnung zu hoch? Tipp: SMS und MMS mit GMX Seien Sie so frei: Alle Infos unter http://www.gmx.net/de/go/freesms |