I find it quite surprising that the existing method is actually better! and just to serve my own ego I extended the benchmark with my method. The results are:
Elapsed method 1 = 178816721
Elapsed method 2 = 571406491
Elapsed method 3 = 136158715
java.vm.version=1.6.0_02-b05
java.vm.name=Java HotSpot(TM) 64-Bit Server VM
os.name=Windows Vista
true
And given that it is a mini benchmark I tried to move them around a little and got this also:
Elapsed method 3 = 76254315
Elapsed method 1 = 190396475
Elapsed method 2 = 604831410
java.vm.version=1.6.0_02-b05
java.vm.name=Java HotSpot(TM) 64-Bit Server VM
os.name=Windows Vista
true
Not sure why this is the case. Any ideas?
Will try to attach the extended and slightly altered benchmark.
Hi,
I am not sure I am allowed to paste code into this comment field so I will try to describe another approach in words. Looking at the patch, it seems you can get the actual Class object for free, so why not just identify-compare that to the Class objects for the primitive types? You avoid the overhead of a native call, and being pure java, I think (pure speculation) that the JIT would have an easier time compiling it. This is obviously just an extreme mini optimization (compared to the patch) but I thought I would chime in regardless