[foreign-memaccess+abi] RFR: Add benchmarks to MemorySegmentVsBits [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Jan 5 16:22:13 UTC 2023


On Wed, 4 Jan 2023 08:00:15 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> This PR proposes the addition of some benchmarks, for example using a LonBuffer and a VarHandle.
>
> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Change to big endian for some variants

Tried (for fun) a version which uses bulk copy:


Benchmark                                      (size)  Mode  Cnt    Score   Error  Units
MemorySegmentVsBits.bitsEquivalent                  1  avgt   30    4.480 ? 0.074  ns/op
MemorySegmentVsBits.bitsEquivalent                  2  avgt   30    6.183 ? 0.066  ns/op
MemorySegmentVsBits.bitsEquivalent                 16  avgt   30   30.993 ? 0.297  ns/op
MemorySegmentVsBits.bitsEquivalent                 64  avgt   30  118.065 ? 1.362  ns/op
MemorySegmentVsBits.bitsEquivalent                256  avgt   30  469.725 ? 4.120  ns/op
MemorySegmentVsBits.byteBuffer                      1  avgt   30    3.956 ? 0.015  ns/op
MemorySegmentVsBits.byteBuffer                      2  avgt   30    4.423 ? 0.053  ns/op
MemorySegmentVsBits.byteBuffer                     16  avgt   30   11.038 ? 0.125  ns/op
MemorySegmentVsBits.byteBuffer                     64  avgt   30   23.274 ? 0.262  ns/op
MemorySegmentVsBits.byteBuffer                    256  avgt   30  117.765 ? 2.430  ns/op
MemorySegmentVsBits.byteVarHandle                   1  avgt   30    2.315 ? 0.031  ns/op
MemorySegmentVsBits.byteVarHandle                   2  avgt   30    2.679 ? 0.063  ns/op
MemorySegmentVsBits.byteVarHandle                  16  avgt   30    5.235 ? 0.032  ns/op
MemorySegmentVsBits.byteVarHandle                  64  avgt   30    8.461 ? 0.076  ns/op
MemorySegmentVsBits.byteVarHandle                 256  avgt   30   19.182 ? 0.268  ns/op
MemorySegmentVsBits.longBuffer                      1  avgt   30    2.778 ? 0.050  ns/op
MemorySegmentVsBits.longBuffer                      2  avgt   30    3.077 ? 0.046  ns/op
MemorySegmentVsBits.longBuffer                     16  avgt   30    6.950 ? 0.103  ns/op
MemorySegmentVsBits.longBuffer                     64  avgt   30   17.435 ? 0.229  ns/op
MemorySegmentVsBits.longBuffer                    256  avgt   30   60.646 ? 0.987  ns/op
MemorySegmentVsBits.panamaHeap                      1  avgt   30    4.989 ? 0.074  ns/op
MemorySegmentVsBits.panamaHeap                      2  avgt   30    6.482 ? 0.019  ns/op
MemorySegmentVsBits.panamaHeap                     16  avgt   30   10.841 ? 0.132  ns/op
MemorySegmentVsBits.panamaHeap                     64  avgt   30   21.987 ? 0.246  ns/op
MemorySegmentVsBits.panamaHeap                    256  avgt   30   66.306 ? 0.457  ns/op
MemorySegmentVsBits.panamaHeapBulk                  1  avgt   30    4.434 ? 0.011  ns/op
MemorySegmentVsBits.panamaHeapBulk                  2  avgt   30    4.855 ? 0.122  ns/op
MemorySegmentVsBits.panamaHeapBulk                 16  avgt   30    5.052 ? 0.061  ns/op
MemorySegmentVsBits.panamaHeapBulk                 64  avgt   30    8.181 ? 0.113  ns/op
MemorySegmentVsBits.panamaHeapBulk                256  avgt   30   23.111 ? 5.388  ns/op
MemorySegmentVsBits.panamaNative                    1  avgt   30    5.138 ? 0.074  ns/op
MemorySegmentVsBits.panamaNative                    2  avgt   30    6.458 ? 0.057  ns/op
MemorySegmentVsBits.panamaNative                   16  avgt   30   10.403 ? 0.033  ns/op
MemorySegmentVsBits.panamaNative                   64  avgt   30   21.548 ? 0.107  ns/op
MemorySegmentVsBits.panamaNative                  256  avgt   30   66.500 ? 0.620  ns/op
MemorySegmentVsBits.panamaNativeBulk                1  avgt   30    4.631 ? 0.066  ns/op
MemorySegmentVsBits.panamaNativeBulk                2  avgt   30    4.795 ? 0.069  ns/op
MemorySegmentVsBits.panamaNativeBulk               16  avgt   30    4.812 ? 0.064  ns/op
MemorySegmentVsBits.panamaNativeBulk               64  avgt   30    8.233 ? 0.058  ns/op
MemorySegmentVsBits.panamaNativeBulk              256  avgt   30   17.950 ? 0.148  ns/op
MemorySegmentVsBits.panamaNativeUnaligned           1  avgt   30    5.098 ? 0.080  ns/op
MemorySegmentVsBits.panamaNativeUnaligned           2  avgt   30    6.654 ? 0.093  ns/op
MemorySegmentVsBits.panamaNativeUnaligned          16  avgt   30   10.442 ? 0.161  ns/op
MemorySegmentVsBits.panamaNativeUnaligned          64  avgt   30   22.153 ? 0.280  ns/op
MemorySegmentVsBits.panamaNativeUnaligned         256  avgt   30   66.498 ? 1.033  ns/op
MemorySegmentVsBits.panamaNativeUnalignedBulk       1  avgt   30    4.410 ? 0.028  ns/op
MemorySegmentVsBits.panamaNativeUnalignedBulk       2  avgt   30    4.934 ? 0.208  ns/op
MemorySegmentVsBits.panamaNativeUnalignedBulk      16  avgt   30    5.017 ? 0.151  ns/op
MemorySegmentVsBits.panamaNativeUnalignedBulk      64  avgt   30    9.527 ? 1.611  ns/op
MemorySegmentVsBits.panamaNativeUnalignedBulk     256  avgt   30   24.086 ? 5.510  ns/op


It seems to outperform the others, at least for big enough sizes.

For the records - the extra benchmarks are here:


@Benchmark
    public void panamaHeapBulk() {
        MemorySegment.copy(longs, 0, segment, JAVA_LONG_UNALIGNED, 0, size);
    }

    @Benchmark
    public void panamaNativeBulk() {
        MemorySegment.copy(longs, 0, nativeSegment, JAVA_LONG, 0, size);
    }

    @Benchmark
    public void panamaNativeUnalignedBulk() {
        MemorySegment.copy(longs, 0, nativeSegment, JAVA_LONG_UNALIGNED, 0, size);
    }

-------------

PR: https://git.openjdk.org/panama-foreign/pull/762


More information about the panama-dev mailing list