mirror of
https://gitlab.uni-marburg.de/langbeid/powersort.git
synced 2025-01-21 19:50:35 +01:00
128 lines
3.2 KiB
Markdown
128 lines
3.2 KiB
Markdown
# Bring Powersort to Java
|
|
|
|
Implementation of Powersort with the aim of integrating it into OpenJDK. Benchmarks are used to ensure that the runtime of the new sorting algorithm is never slower than the current Timsort implementation.
|
|
|
|
<!-- TOC -->
|
|
* [Bring Powersort to Java](#bring-powersort-to-java)
|
|
* [Setup](#setup)
|
|
* [Development Setup with nix](#development-setup-with-nix)
|
|
* [Tasks](#tasks)
|
|
* [Test Cases](#test-cases)
|
|
* [Benchmark](#benchmark)
|
|
* [Custom](#custom)
|
|
* [JMH](#jmh)
|
|
<!-- TOC -->
|
|
|
|
## Setup
|
|
|
|
We use Gradle for dependency and build management.
|
|
|
|
**Commandline**
|
|
|
|
Check which Java toolchains Gradle finds:
|
|
|
|
```shell
|
|
./gradlew javaToolchains
|
|
```
|
|
|
|
This should include version >= 23, e.g.:
|
|
|
|
```
|
|
+ N/A JDK 23-ga
|
|
| Location: /nix/store/48290hnlb13xmwjw9y16a1s785993bv7-openjdk-23-ga/lib/openjdk
|
|
| Language Version: 23
|
|
| Vendor: N/A
|
|
| Architecture: amd64
|
|
| Is JDK: true
|
|
| Detected by: Current JVM
|
|
```
|
|
|
|
### Development Setup with nix
|
|
|
|
The provided [./shell.nix](./shell.nix) file can be used to set up a development environment with IntelliJ. The only prerequisite is to have a working `nix` installation for which there are multiple possibilities, e.g:
|
|
|
|
```shell
|
|
# https://github.com/DeterminateSystems/nix-installer?tab=readme-ov-file#determinate-nix-installer
|
|
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | \
|
|
sh -s -- install
|
|
```
|
|
|
|
Then the dependencies (JDK23, Gradle, IntelliJ) can be installed with:
|
|
|
|
```shell
|
|
nix-shell
|
|
```
|
|
|
|
**IntelliJ**
|
|
|
|
When using `nix-shell`, some manual configuration is necessary:
|
|
|
|
- `STRG` `ALT` `SHIFT` `s` -> SDK -> add JDK ->
|
|
- home path: `/usr/lib/openjdk`
|
|
- name: `usr-lib-jdk`
|
|
- `STRG` `ALT` `s` -> build tools -> gradle ->
|
|
- local installation: `/usr/lib/gradle`
|
|
- Gradle JVM: `usr-lib-jdk`
|
|
|
|
## Tasks
|
|
|
|
List all Gradle tasks which can be run:
|
|
|
|
```shell
|
|
./gradlew tasks
|
|
```
|
|
|
|
This can also be done graphically in IntelliJ:
|
|
|
|
![intellij-gradle.png](intellij-gradle.png)
|
|
|
|
## Test Cases
|
|
|
|
Run the task "test":
|
|
|
|
```shell
|
|
./gradlew test
|
|
```
|
|
|
|
## Benchmark
|
|
|
|
There are two different benchmarks. One is based on the JMH benchmark framework, the other one is a custom benchmark implementation.
|
|
|
|
### Custom
|
|
|
|
Run Custom Benchmark (CGM) with
|
|
|
|
- Custom Generated Lists (CGL):
|
|
|
|
```shell
|
|
./gradlew runCbmCgl
|
|
```
|
|
|
|
- Powersort competition lists:
|
|
|
|
```shell
|
|
./gradlew runCbmCompetition
|
|
```
|
|
|
|
### JMH
|
|
|
|
#### Run JMH with CGL and Powersort competition lists
|
|
|
|
```shell
|
|
./gradlew jmh
|
|
```
|
|
|
|
- To benchmark only one of the different list collections, see `jmh { excludes }` at the bottom of [./app/build.gradle.kts](./app/build.gradle.kts).
|
|
|
|
#### IntelliJ plugin
|
|
|
|
The [JMH Java Microbenchmark Harness](https://plugins.jetbrains.com/plugin/7529-jmh-java-microbenchmark-harness) plugin allows running benchmarks from within the IDE in a similar way as JUnit test cases. This can be used for development but yields less accurate results.
|
|
|
|
![intellij-jmh.png](intellij-jmh.png)
|
|
|
|
#### Further notes
|
|
|
|
- JHM: https://github.com/openjdk/jmh?tab=readme-ov-file#other-build-systems
|
|
- We use the JMH Gradle plugin: https://github.com/melix/jmh-gradle-plugin
|
|
- Sample JMH Gradle project: https://github.com/twoVersatile/jmhsample
|