MarginaliaSearch/code/libraries/array/cpp
Jaseem Abid 0dd14a4bd0 Specify C++ standard in build command
The default C++ language standard on macOS is gnu++98, which won't build
this module.

Full error:

```
> Task :code:libraries:array:cpp:compileCpp FAILED
src/main/cpp/cpphelpers.cpp:28:5: error: expected expression
    [](const p64x2& fst, const p64x2& snd) {
    ^
```
2024-06-12 12:47:10 +01:00
..
java/nu/marginalia (array) Clean up search function jungle 2024-05-17 14:30:06 +02:00
resources Don't track build files(libcpp.so) with git 2024-06-12 12:45:49 +01:00
src/main (array) Clean up search function jungle 2024-05-17 14:30:06 +02:00
.gitignore Don't track build files(libcpp.so) with git 2024-06-12 12:45:49 +01:00
build.gradle (array) Clean up native code a bit 2024-05-16 14:47:10 +02:00
compile.sh Specify C++ standard in build command 2024-06-12 12:47:10 +01:00
readme.md (array, experimental) Add benchmark results for quicksort 2024-05-14 18:15:30 +02:00

LongArray C++ Helpers

This package contains helper functions for working with LongArray objects, as native C++ calls. The helpers are only built on Linux, and if they are absent, Java substitutes should be used instead.

Library loading and access is available through the NativeAlgos class.

Note that the C++ helpers are compiled with march=native by default, so they are not portable between different CPU architectures.

This provides a speedup for some operations, especially when compared to using MemorySegment's get methods and not Unsafe.

Benchmarks

JMH benchmark results for 64 bit quicksort N=2^10, 25 trials, graalvm 21.0.3:

Implementation Throughput ops/s Error p=99%
native 114.877 4.216
unsafe 98.443 2.723
memorysegment 72.492 1.980

Note that odds are stacked in favor of the native implementation since the dataset is fairly large, meaning the call overhead is less significant. For smaller datasets, the overhead of native calls may be a bigger factor.