[Fwd: Re: hg: jdk7/tl/jdk: 6642323: Speeding up Single Byte Decoders; ...]
Ulf Zibis
Ulf.Zibis at gmx.de
Sat Jan 17 13:18:57 PST 2009
Am 17.01.2009 21:09, Christian Thalinger schrieb:
> I decided to write my own, very simple micro-benchmark. In the
> following benchmark I get a speedup of about 0.9%:
>
> void foo() {
> byte[] ba = new byte[255];
> char[] ca = new char[255];
> for (int i = 0; i < 10000000; i++) {
> bar(ba, ca);
> }
> }
>
> void bar(byte[] ba, char[] ca) {
> for (int i = 0; i < ba.length; i++) {
> ca[i] = decode(ba[i]);
> }
> }
>
> public char decode(byte a) {
> return (char) (a & 0xFF);
> }
>
> That speedup is quite OK but I doubt you will get as much in your tests.
> But still, there's some room left for other optimizations. Maybe I can
> look into them too.
>
> -- Christian
>
>
>
Hi,
do you mean 0.9 % against +128 trick. This would be good result, because
then we could get rid of this trick, and the maps must not be swapped
before.
Maybe there is more difference if buffer's are longer?
Why you choose byte[255] against byte[256] ?
What's about filling the buffers with values before?:
for (int i=0; i<map.length; i++)
map[i] = (char)i;
for (int i=0; i<src.length; i++)
src[i] = (byte)i;
Can you also try with map ?:
char[] map = new char[256];
void foo() {
byte[] src = new byte[16384];
char[] dst = new char[16384];
for (int i=0; i<1000000; i++) {
bar(src, dst);
}
}
void bar(byte[] src, char[] dst) {
for (int i=0; i<src.length; i++) {
dst[i] = decode(src[i]);
}
}
public char decode(byte a) {
return map[a & 0xFF];
}
Is there any difference, if you inline the decode method into the for loop?
-Ulf
More information about the hotspot-dev
mailing list