forked from Parallele_Programmierung/Labs
initial
parent
5aa83f1b3d
commit
f6c4ac8bcc
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Justfile (https://just.systems/) for starting Maven standard targets
|
||||||
|
|
||||||
|
default: clean compile package
|
||||||
|
just exec pp.Main ""
|
||||||
|
|
||||||
|
exec class args: compile
|
||||||
|
mvn exec:java -Dexec.args="{{args}}" -Dexec.mainClass={{class}}
|
||||||
|
# exec class args:
|
||||||
|
# java -cp target/app.jar {{class}} {{args}}
|
||||||
|
clean:
|
||||||
|
mvn clean
|
||||||
|
compile:
|
||||||
|
mvn compile
|
||||||
|
test: compile
|
||||||
|
mvn test
|
||||||
|
javadoc:
|
||||||
|
mvn javadoc:javadoc
|
||||||
|
package:
|
||||||
|
mvn package
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>pp</groupId>
|
||||||
|
<artifactId>pp.09.01-Fiber</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.release>23</maven.compiler.release>
|
||||||
|
<lombok.version>edge-SNAPSHOT</lombok.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency><!-- für Unit-Tests -->
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>5.10.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency><!-- für Lombok -->
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>${lombok.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency><!-- für net.jcip Annotationen -->
|
||||||
|
<groupId>net.jcip</groupId>
|
||||||
|
<artifactId>jcip-annotations</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin><!-- für Unit-Tests [mvn test] -->
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin><!-- [mvn compile] -->
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.9.0</version>
|
||||||
|
<configuration>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>${lombok.version}</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin><!-- [mvn exec:java] -->
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin><!-- [mvn javadoc:javadoc] -->
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>3.5.0</version>
|
||||||
|
<configuration>
|
||||||
|
<show>private</show>
|
||||||
|
<locale>en_US</locale>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package pp;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
private final static int NUM = 100;
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
pp.fiber.Performance.main();
|
||||||
|
pp.fiber.first.ThreadPerformance.main();
|
||||||
|
pp.fiber.first.FiberPerformance.main();
|
||||||
|
pp.fiber.second.ThreadPerformance.main(String.valueOf(NUM));
|
||||||
|
pp.fiber.second.FiberPerformance.main(String.valueOf(NUM));
|
||||||
|
pp.fiber.second.FiberPerformance.main(String.valueOf(NUM*10));
|
||||||
|
pp.fiber.second.FiberPerformance.main(String.valueOf(NUM*100));
|
||||||
|
pp.fiber.second.FiberPerformance.main(String.valueOf(NUM*1000));
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package pp.fiber;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class Performance {
|
||||||
|
static long now;
|
||||||
|
|
||||||
|
public static void main(String... args) throws InterruptedException {
|
||||||
|
now = System.nanoTime();
|
||||||
|
now = System.nanoTime() - now;
|
||||||
|
System.out.printf("Zeitdauer zwischen zwei Instruktionen (Baseline \"Minimum\"): %3.3f ms\n", now / 1000.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package pp.fiber.first;
|
||||||
|
|
||||||
|
|
||||||
|
public class FiberPerformance {
|
||||||
|
static long now;
|
||||||
|
|
||||||
|
public static void main(String... args) throws InterruptedException {
|
||||||
|
now = System.nanoTime();
|
||||||
|
var t = Thread.ofVirtual()
|
||||||
|
.unstarted(() -> now = System.nanoTime() - now);
|
||||||
|
t.start();
|
||||||
|
t.join();
|
||||||
|
System.out.printf("Fast leerer virtueller Thread Starten bis Ende (Baseline: \"Fiber\": %3.3f ns\n", now / 1000.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package pp.fiber.first;
|
||||||
|
|
||||||
|
|
||||||
|
public class ThreadPerformance {
|
||||||
|
static long now;
|
||||||
|
|
||||||
|
public static void main(String... args) throws InterruptedException {
|
||||||
|
now = System.nanoTime();
|
||||||
|
var t = new Thread(() -> now = System.nanoTime() - now);
|
||||||
|
t.start();
|
||||||
|
t.join();
|
||||||
|
System.out.printf("Fast leerer Plattform-Thread Starten bis Ende (Baseline: \"Thread\": %3.3f ns\n", now / 1000.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package pp.fiber.second;
|
||||||
|
|
||||||
|
public class FiberPerformance {
|
||||||
|
static long now;
|
||||||
|
|
||||||
|
public static void main(String... args) throws InterruptedException {
|
||||||
|
var NUM = 100;
|
||||||
|
if (args.length == 1) {
|
||||||
|
NUM = Integer.valueOf(args[0]);
|
||||||
|
}
|
||||||
|
var threads = new Thread[NUM];
|
||||||
|
for (var i = 0; i < Integer.valueOf(NUM); i++) {
|
||||||
|
threads[i] = Thread.ofVirtual().unstarted(() -> {
|
||||||
|
while (true)
|
||||||
|
Thread.yield();
|
||||||
|
});
|
||||||
|
threads[i].start(); // 1. virt. Thread: "Endlos-Daemon"
|
||||||
|
}
|
||||||
|
now = System.nanoTime();
|
||||||
|
var t = Thread.ofVirtual()
|
||||||
|
.unstarted(() -> now = System.nanoTime() - now);
|
||||||
|
t.start();
|
||||||
|
t.join();
|
||||||
|
System.out.printf("Virtueller Thread Nr. %d starten und beenden (%d virtuelle Threads laufen bereits endlos) %3.3f ns\n", NUM+1, NUM, now / 1000.0);
|
||||||
|
for (var i = 0; i < Integer.valueOf(NUM); i++) {
|
||||||
|
threads[i].interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package pp.fiber.second;
|
||||||
|
|
||||||
|
public class ThreadPerformance {
|
||||||
|
static long now;
|
||||||
|
|
||||||
|
public static void main(String... args) throws InterruptedException {
|
||||||
|
var NUM = 100;
|
||||||
|
if (args.length == 1) {
|
||||||
|
NUM = Integer.valueOf(args[0]);
|
||||||
|
}
|
||||||
|
var threads = new Thread[NUM];
|
||||||
|
for (var i = 0; i < Integer.valueOf(NUM); i++) {
|
||||||
|
threads[i] = new Thread(() -> {
|
||||||
|
while (true)
|
||||||
|
Thread.yield();
|
||||||
|
});
|
||||||
|
threads[i].start(); // 1. virt. Thread: "Endlos-Daemon"
|
||||||
|
}
|
||||||
|
|
||||||
|
now = System.nanoTime();
|
||||||
|
|
||||||
|
var t = new Thread(() -> now = System.nanoTime() - now);
|
||||||
|
t.start();
|
||||||
|
t.join();
|
||||||
|
System.out.printf("Plattform Thread Nr. %d starten und beenden (%d Plattform-Threads laufen bereits endlos) %3.3f ns\n", NUM+1, NUM, now / 1000.0);
|
||||||
|
for (var i = 0; i < Integer.valueOf(NUM); i++) {
|
||||||
|
threads[i].interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue