Bläddra i källkod

adding xdevs-java benchmarks init commit

Snej69420 5 månader sedan
förälder
incheckning
a1b8728e17

+ 27 - 0
benchmarks/xdevs-java/pom.xml

@@ -0,0 +1,27 @@
+<project>
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.benchmarks</groupId>
+    <artifactId>xdevs-benchmark</artifactId>
+    <version>1.0</version>
+
+    <dependencies>
+        <dependency>
+            <groupId>xdevs</groupId>
+            <artifactId>xdevs</artifactId>
+            <version>24.04</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.11.0</version>
+                <configuration>
+                    <source>21</source> <target>21</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 63 - 0
benchmarks/xdevs-java/src/main/java/DelayedAtomic.java

@@ -0,0 +1,63 @@
+package benchmarks;
+
+import xdevs.core.modeling.Atomic;
+import xdevs.core.modeling.Port;
+import xdevs.core.examples.devstone.Dhrystone;
+
+public class DelayedAtomic extends Atomic {
+    private enum STATE {Passive, Active}
+
+    public Port<Integer> iIn = new Port<>("i_in");
+    public Port<Integer> oOut;
+
+    protected STATE state = Passive
+    protected double preparationTime, intDelay, extDelay;
+    protected boolean hasOutPort, stats;
+    public long intCount = 0, extCount = 0;
+
+    public DelayedAtomic(String name, double prepTime, double intDelay, double extDelay, boolean hasOutPort, boolean stats) {
+        super(name);
+        this.preparationTime = prepTime;
+        this.intDelay = intDelay;
+        this.extDelay = extDelay;
+        this.hasOutPort = hasOutPort;
+        this.stats = stats;
+
+        super.addInPort(iIn);
+        if (hasOutPort) {
+            this.oOut = new Port<>("o_out");
+            super.addOutPort(oOut);
+        }
+    }
+
+    @Override
+    public void initialize() {
+        super.passivate();
+    }
+
+    @Override
+    public void deltint() {
+        if (stats) intCount++;
+
+        if (intDelay > 0.0) Dhrystone.execute(intDelay);
+
+        super.passivate();
+    }
+
+    @Override
+    public void deltext(double e) {
+        super.resume(e);
+        if (stats) extCount++; 
+
+        if (extDelay > 0.0) Dhrystone.execute(extDelay);
+
+        super.holdIn(STATE.Active, preparationTime);
+    }
+
+    @Override
+    public void lambda() {
+        if (hasOutPort) {
+            oOut.addValue(0); 
+        }
+    }
+}

+ 52 - 0
benchmarks/xdevs-java/src/main/java/Generator.java

@@ -0,0 +1,52 @@
+package benchmarks;
+
+import xdevs.core.modeling.Atomic;
+import xdevs.core.modeling.Port;
+
+public class Generator extends Atomic {
+    public Port<int> oOut = new Port<>("o_out");
+
+    private final double period;
+    private int cycles;
+    private final int output;
+
+    public Generator(String name, double period, int cycles, int output) {
+        super(name);
+        super.addOutPort(oOut);
+
+        this.period = period;
+        this.cycles = cycles;
+        this.output = output;
+    }
+
+    @Override
+    public void initialize() {
+        if (cycles > 0) {
+            this.holdIn(cycles, period);
+        } else {
+            this.passivate();
+        }
+    }
+
+    @Override
+    public void deltint() {
+        cycles--;
+        if (cycles > 0) {
+            this.holdIn(cycles, period);
+        } else {
+            this.passivate();
+        }
+    }
+
+    @Override
+    public void lambda() {
+        if (cycles > 0) {
+            oOut.addValue(output);
+        }
+    }
+
+    @Override
+    public void deltext(double e) {
+        super.passivate();
+    }
+}

+ 0 - 0
benchmarks/xdevs-java/src/main/java/Main.java