added jvms

This commit is contained in:
didier committed 2024-09-10 15:40:03 -04:00
1 parent 1fab7b30c1
commit 124d29a99d
2 files changed
+39 -44

No files matched your search

+6 -8
View File
@@ -7,8 +7,8 @@
let
pkgs = nixpkgs.legacyPackages.${system};
pname = "stream-examples";
benchmark = pkgs.maven.buildMavenPackage {
mvnJdk = pkgs.jdk22;
benchmark = (jdk : pkgs.maven.buildMavenPackage {
mvnJdk = jdk;
pname = pname;
version = "0.1.0";
src = ./.;
@@ -16,21 +16,19 @@
mvnHash = "sha256-G7PQd0Ul61m+C9S7OvAB6NkMxRM8AMYg5+1G0RQeXP8=";
installPhase = ''
ls -lrth
mkdir -p $out/bin $out/share/${pname}
install -Dm644 target/stream-examples.jar $out/share/${pname}/${pname}.jar
echo 'didier rocks!'
mkdir -p $out/bin $out/share/${pname}
makeWrapper ${pkgs.jdk22}/bin/java $out/bin/${pname} \
makeWrapper ${jdk}/bin/java $out/bin/${pname} \
--add-flags "-jar $out/share/${pname}/${pname}.jar"
'';
};
});
in
{
packages = {
benchmark = benchmark;
benchmark-openjdk = benchmark pkgs.jdk22;
benchmark-graal = benchmark pkgs.graalvm-ce;
};
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
@@ -1,15 +1,22 @@
package com.alldressedprogramming;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
@State(Scope.Thread)
@@ -52,22 +59,6 @@ public class Main {
final List<Album> albums = createFakeAlbums(10_000);
@Benchmark
public void classical(Blackhole blackhole) {
List<Song> newTaylorSwift = new ArrayList<>();
for(Album album: albums){
if(album.releaseYear() > 2020){
for(Song song: album.songs()){
if(song.composers().contains("taylor swift")){
newTaylorSwift.add(song);
}
}
}
}
blackhole.consume(newTaylorSwift);
}
public List<Album> getRecentAlbums(List<Album> albums) {
List<Album> ret = new ArrayList<>();
for (Album album : albums) {
@@ -90,22 +81,6 @@ public class Main {
return ret;
}
@Benchmark
public void brokenDownWithMethodsWith10Duplicates(Blackhole blackhole) {
for(int i = 0; i < 10; i++){
List<Album> recentAlbums = getRecentAlbums(albums);
List<Song> newTaylorSwift = getTaylorSwiftSongs(recentAlbums);
blackhole.consume(newTaylorSwift);
}
}
@Benchmark
public void brokenDownWithMethods(Blackhole blackhole) {
List<Album> recentAlbums = getRecentAlbums(albums);
List<Song> newTaylorSwift = getTaylorSwiftSongs(recentAlbums);
blackhole.consume(newTaylorSwift);
}
public Stream<Album> getRecentAlbumsAsStream(Stream<Album> albums) {
return albums.filter(album -> album.releaseYear() > 2020);
}
@@ -116,6 +91,28 @@ public class Main {
.filter(song -> song.composers().contains("taylor swift"));
}
@Benchmark
public void classical(Blackhole blackhole) {
List<Song> newTaylorSwift = new ArrayList<>();
for(Album album: albums){
if(album.releaseYear() > 2020){
for(Song song: album.songs()){
if(song.composers().contains("taylor swift")){
newTaylorSwift.add(song);
}
}
}
}
blackhole.consume(newTaylorSwift);
}
@Benchmark
public void brokenDownWithMethods(Blackhole blackhole) {
List<Album> recentAlbums = getRecentAlbums(albums);
List<Song> newTaylorSwift = getTaylorSwiftSongs(recentAlbums);
blackhole.consume(newTaylorSwift);
}
@Benchmark
public void brokenDownWithMethodsWithStreams(Blackhole blackhole) {
Stream<Album> recentAlbums = getRecentAlbumsAsStream(albums.stream());