benchmark unaligned memory access
YC Huang
ychuang_cn at hotmail.com
Wed Mar 4 10:24:04 UTC 2015
Hi,
I'm trying to benchmark what's the cost between aligned/unaligned memory access,but my test-case doesn't show there's obvious performance difference when running on my laptop(Pentium 6200). Am I doing something wrong in the Test? Thank you...
BR,YC Huang
following is the test code:
@State(Scope.Thread)public class MemoryAccessTest { private long alignedAddr, unalignedAddr;
@Param({ "24" }) public int structSize;
public static Unsafe unsafe; static { try { Field field = Unsafe.class.getDeclaredField("theUnsafe"); field.setAccessible(true); unsafe = (Unsafe) field.get(null); } catch (Exception e) { } }
@Setup public void init() { alignedAddr = unsafe.allocateMemory(structSize); assert alignedAddr % 8 == 0;
unalignedAddr = alignedAddr + 9;// }
@Benchmark public long alignedMemAccess() { return unsafe.getLong(alignedAddr); }
@Benchmark public long unalignedMemAccess() { return unsafe.getLong(unalignedAddr); }}
More information about the jmh-dev
mailing list