added jvms
This commit is contained in:
1 parent
1fab7b30c1
commit
124d29a99d
2 files changed
+49
-54
No files matched your search
@@ -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,6 +59,38 @@ public class Main {
|
||||
|
||||
final List<Album> albums = createFakeAlbums(10_000);
|
||||
|
||||
public List<Album> getRecentAlbums(List<Album> albums) {
|
||||
List<Album> ret = new ArrayList<>();
|
||||
for (Album album : albums) {
|
||||
if (album.releaseYear() > 2020) {
|
||||
ret.add(album);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<Song> getTaylorSwiftSongs(List<Album> albums) {
|
||||
List<Song> ret = new ArrayList<>();
|
||||
for (Album album : albums) {
|
||||
for (Song song : album.songs()) {
|
||||
if (song.composers().contains("taylor swift")) {
|
||||
ret.add(song);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Stream<Album> getRecentAlbumsAsStream(Stream<Album> albums) {
|
||||
return albums.filter(album -> album.releaseYear() > 2020);
|
||||
}
|
||||
|
||||
public Stream<Song> getTaylorSwiftSongsAsStream(Stream<Album> albums) {
|
||||
return albums
|
||||
.flatMap(album -> album.songs().stream())
|
||||
.filter(song -> song.composers().contains("taylor swift"));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void classical(Blackhole blackhole) {
|
||||
List<Song> newTaylorSwift = new ArrayList<>();
|
||||
@@ -67,38 +106,6 @@ public class Main {
|
||||
blackhole.consume(newTaylorSwift);
|
||||
}
|
||||
|
||||
|
||||
public List<Album> getRecentAlbums(List<Album> albums){
|
||||
List<Album> ret = new ArrayList<>();
|
||||
for(Album album: albums){
|
||||
if(album.releaseYear() > 2020){
|
||||
ret.add(album);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<Song> getTaylorSwiftSongs(List<Album> albums){
|
||||
List<Song> ret = new ArrayList<>();
|
||||
for(Album album: albums){
|
||||
for(Song song: album.songs()){
|
||||
if(song.composers().contains("taylor swift")){
|
||||
ret.add(song);
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
@@ -106,16 +113,6 @@ public class Main {
|
||||
blackhole.consume(newTaylorSwift);
|
||||
}
|
||||
|
||||
public Stream<Album> getRecentAlbumsAsStream(Stream<Album> albums){
|
||||
return albums.filter(album -> album.releaseYear() > 2020);
|
||||
}
|
||||
|
||||
public Stream<Song> getTaylorSwiftSongsAsStream(Stream<Album> albums){
|
||||
return albums
|
||||
.flatMap(album -> album.songs().stream())
|
||||
.filter(song -> song.composers().contains("taylor swift"));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void brokenDownWithMethodsWithStreams(Blackhole blackhole) {
|
||||
Stream<Album> recentAlbums = getRecentAlbumsAsStream(albums.stream());
|
||||
|
||||
Reference in new issue
Block a user