added nix
This commit is contained in:
1 parent
61700e7b59
commit
1fab7b30c1
11 files changed
+334
-13
No files matched your search
@@ -0,0 +1,3 @@
|
||||
target
|
||||
result
|
||||
.direnv
|
||||
Generated
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="stream-examples" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+20
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
```
|
||||
# VM version: JDK 22.0.2, OpenJDK 64-Bit Server VM, 22.0.2+9-jvmci-b01
|
||||
# VM invoker: /nix/store/lschm1if5f45qf8zwr5z7h0afhd00gd4-graalvm-ce-22.0.2/bin/java
|
||||
# VM options: -XX:ThreadPriorityPolicy=1 -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCIProduct -XX:-UnlockExperimentalVMOptions -javaagent:/nix/store/0y08ljcqmrqrcmjcx7zvx9k3haifhx0q-idea-ultimate-2024.2.0.2/idea-ultimate/lib/idea_rt.jar=40733:/nix/store/0y08ljcqmrqrcmjcx7zvx9k3haifhx0q-idea-ultimate-2024.2.0.2/idea-ultimate/bin -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8
|
||||
# Blackhole mode: compiler (auto-detected, use -Djmh.blackhole.autoDetect=false to disable)
|
||||
|
||||
Benchmark Mode Cnt Score Error Units
|
||||
Main.brokenDownWithMethods thrpt 25 6815.783 ± 106.436 ops/s
|
||||
Main.brokenDownWithMethodsWithStreams thrpt 25 6178.742 ± 85.668 ops/s
|
||||
Main.classical thrpt 25 5780.151 ± 19.606 ops/s
|
||||
```
|
||||
Generated
+61
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1725634671,
|
||||
"narHash": "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "574d1eac1c200690e27b8eb4e24887f8df7ac27c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs",
|
||||
"utils": "utils"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
outputs = { self, nixpkgs, utils }: utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
pname = "stream-examples";
|
||||
benchmark = pkgs.maven.buildMavenPackage {
|
||||
mvnJdk = pkgs.jdk22;
|
||||
pname = pname;
|
||||
version = "0.1.0";
|
||||
src = ./.;
|
||||
nativeBuildInputs = [ pkgs.makeWrapper ];
|
||||
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} \
|
||||
--add-flags "-jar $out/share/${pname}/${pname}.jar"
|
||||
'';
|
||||
|
||||
};
|
||||
in
|
||||
{
|
||||
packages = {
|
||||
benchmark = benchmark;
|
||||
};
|
||||
devShell = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
jdk22
|
||||
maven
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -4,9 +4,9 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<groupId>org.all-dressed-programming</groupId>
|
||||
<artifactId>stream-examples</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>22</maven.compiler.source>
|
||||
@@ -27,4 +27,38 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-help-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<manifestEntries>
|
||||
<Main-Class>com.alldressedprogramming.Main</Main-Class>
|
||||
<Build-Number>1</Build-Number>
|
||||
</manifestEntries>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.alldressedprogramming;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
@@ -11,7 +12,12 @@ import java.util.stream.LongStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
@State(Scope.Thread)
|
||||
@Fork( 1 )
|
||||
@Warmup( iterations = 2 )
|
||||
@Measurement( iterations = 10 )
|
||||
@BenchmarkMode( Mode.AverageTime )
|
||||
@OutputTimeUnit( TimeUnit.MICROSECONDS )
|
||||
public class Main {
|
||||
|
||||
public record Song(List<String> composers) {
|
||||
@@ -30,7 +36,6 @@ public class Main {
|
||||
}
|
||||
|
||||
public static Album createFakeAlbum(Random random) {
|
||||
var seed = random.nextLong();
|
||||
var songs = IntStream.range(2, 25)
|
||||
.mapToObj(Random::new)
|
||||
.map(Main::createFakeSong)
|
||||
@@ -43,16 +48,9 @@ public class Main {
|
||||
.mapToObj(Random::new)
|
||||
.map(Main::createFakeAlbum)
|
||||
.toList();
|
||||
|
||||
}
|
||||
|
||||
List<Album> albums;
|
||||
|
||||
@Setup(Level.Invocation)
|
||||
public void setUp() {
|
||||
albums = createFakeAlbums(1000);
|
||||
}
|
||||
|
||||
final List<Album> albums = createFakeAlbums(10_000);
|
||||
|
||||
@Benchmark
|
||||
public void classical(Blackhole blackhole) {
|
||||
@@ -92,6 +90,15 @@ 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);
|
||||
@@ -113,10 +120,17 @@ public class Main {
|
||||
public void brokenDownWithMethodsWithStreams(Blackhole blackhole) {
|
||||
Stream<Album> recentAlbums = getRecentAlbumsAsStream(albums.stream());
|
||||
Stream<Song> newTaylorSwift = getTaylorSwiftSongsAsStream(recentAlbums);
|
||||
blackhole.consume(newTaylorSwift);
|
||||
blackhole.consume(newTaylorSwift.toList());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
org.openjdk.jmh.Main.main(args);
|
||||
// var main = new Main();
|
||||
// var albums = Main.createFakeAlbums(100);
|
||||
// List<Album> recentAlbums = main.getRecentAlbums(albums);
|
||||
// List<Song> newTaylorSwift = main.getTaylorSwiftSongs(recentAlbums);
|
||||
// System.out.println(newTaylorSwift.size());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.alldressedprogramming;
|
||||
|
||||
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.Warmup;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Fork( 1 )
|
||||
@Warmup( iterations = 2 )
|
||||
@Measurement( iterations = 10 )
|
||||
@BenchmarkMode( Mode.AverageTime )
|
||||
@OutputTimeUnit( TimeUnit.MILLISECONDS )
|
||||
public class StreamBenchmarks
|
||||
{
|
||||
|
||||
private static final int LIMIT = 10_000;
|
||||
|
||||
enum Foo
|
||||
{
|
||||
ONE( 1 ), TWO( 2 ), THREE( 3 ), FOUR( 4 ), FIVE( 5 ), SIX( 6 ), SEVEN( 7 ), EIGHT( 8 );
|
||||
|
||||
private final int value;
|
||||
|
||||
Foo( int value )
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void iterationWithForLoop( Blackhole blackhole )
|
||||
{
|
||||
for ( int i = 0; i < LIMIT; i++ )
|
||||
{
|
||||
var ret = new ArrayList<Integer>();
|
||||
for ( var foo : Foo.values() )
|
||||
{
|
||||
if ( foo.getValue() % 2 == 0 )
|
||||
{
|
||||
ret.add( foo.getValue() );
|
||||
}
|
||||
}
|
||||
blackhole.consume( ret );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void iterationWithStream( Blackhole blackhole )
|
||||
{
|
||||
for ( int i = 0; i < LIMIT; i++ )
|
||||
{
|
||||
var ret = Stream.of( Foo.values() )
|
||||
.map( Foo::getValue )
|
||||
.filter( x -> x % 2 == 0 )
|
||||
.toList();
|
||||
blackhole.consume( ret );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void findFirstWithForLoop( Blackhole blackhole )
|
||||
{
|
||||
for ( int i = 0; i < LIMIT; i++ )
|
||||
{
|
||||
int ret = -1;
|
||||
for ( var foo : Foo.values() )
|
||||
{
|
||||
if ( foo.getValue() == 6 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
blackhole.consume( ret );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void findFirstWithStream( Blackhole blackhole )
|
||||
{
|
||||
for ( int i = 0; i < LIMIT; i++ )
|
||||
{
|
||||
var ret = Stream.of( Foo.values() )
|
||||
.map( Foo::getValue )
|
||||
.filter( x -> x == 6 )
|
||||
.findFirst()
|
||||
.orElse( -1 );
|
||||
blackhole.consume( ret );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main( String[] args )
|
||||
throws Exception
|
||||
{
|
||||
org.openjdk.jmh.Main.main( args );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user