mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Adding HTML/Java on top of HotSpot VM & JavaFX version of the benchmark.
Use following comand to run the FX version: $ mvn -Pfx clean install exec:java
This commit is contained in:
parent
1c0acf61d4
commit
f7e584d700
|
@ -33,16 +33,19 @@
|
|||
<groupId>org.teavm</groupId>
|
||||
<artifactId>teavm-classlib</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.teavm</groupId>
|
||||
<artifactId>teavm-jso</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.teavm</groupId>
|
||||
<artifactId>teavm-dom</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jbox2d</groupId>
|
||||
|
@ -54,6 +57,7 @@
|
|||
<artifactId>jbox2d-library</artifactId>
|
||||
<version>2.2.1.1</version>
|
||||
<classifier>sources</classifier>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
|
@ -61,6 +65,16 @@
|
|||
<version>2.7.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.dukescript.canvas</groupId>
|
||||
<artifactId>html5-canvas</artifactId>
|
||||
<version>0.7.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.netbeans.html</groupId>
|
||||
<artifactId>net.java.html.boot</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -77,43 +91,69 @@
|
|||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.teavm</groupId>
|
||||
<artifactId>teavm-maven-plugin</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>web-client</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>build-javascript</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
||||
<mainClass>org.teavm.samples.benchmark.teavm.BenchmarkStarter</mainClass>
|
||||
<runtime>SEPARATE</runtime>
|
||||
<minifying>true</minifying>
|
||||
<debugInformationGenerated>true</debugInformationGenerated>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.teamvm.samples.benchmark.htmljava.BenchmarkStarter</mainClass>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<useUniqueVersions>false</useUniqueVersions>
|
||||
</manifest>
|
||||
</archive>
|
||||
<excludes>
|
||||
<exclude>**/gwt/*</exclude>
|
||||
<exclude>**/teavm/*</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>gwt-maven-plugin</artifactId>
|
||||
<version>2.7.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<optimizationLevel>9</optimizationLevel>
|
||||
<compileSourcesArtifacts>
|
||||
<item>org.jbox2d:jbox2d-library</item>
|
||||
</compileSourcesArtifacts>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<groupId>org.teavm</groupId>
|
||||
<artifactId>teavm-maven-plugin</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>web-client</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>build-javascript</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
||||
<mainClass>org.teavm.samples.benchmark.teavm.BenchmarkStarter</mainClass>
|
||||
<runtime>SEPARATE</runtime>
|
||||
<minifying>false</minifying>
|
||||
<debugInformationGenerated>true</debugInformationGenerated>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>gwt-maven-plugin</artifactId>
|
||||
<version>2.7.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<optimizationLevel>9</optimizationLevel>
|
||||
<compileSourcesArtifacts>
|
||||
<item>org.jbox2d:jbox2d-library</item>
|
||||
</compileSourcesArtifacts>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
@ -127,10 +167,47 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.netbeans.html</groupId>
|
||||
<artifactId>html4j-maven-plugin</artifactId>
|
||||
<version>1.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>process-js-annotations</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>fx</id>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.netbeans.html</groupId>
|
||||
<artifactId>net.java.html.boot.fx</artifactId>
|
||||
<version>1.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<configuration>
|
||||
<mainClass>org.teavm.samples.benchmark.htmljava.BenchmarkFX</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright 2015 Jaroslav Tulach.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.samples.benchmark.htmljava;
|
||||
|
||||
import net.java.html.boot.BrowserBuilder;
|
||||
|
||||
public final class BenchmarkFX {
|
||||
private BenchmarkFX() {
|
||||
}
|
||||
|
||||
public static void main(String... args) {
|
||||
BrowserBuilder.newBrowser().loadPage("fx.html")
|
||||
.loadClass(BenchmarkStarter.class)
|
||||
.invoke("main")
|
||||
.showAndWait();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright 2015 Jaroslav Tulach.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.samples.benchmark.htmljava;
|
||||
|
||||
import com.dukescript.api.canvas.GraphicsContext2D;
|
||||
import com.dukescript.api.canvas.Style;
|
||||
import com.dukescript.canvas.html.HTML5Graphics;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import net.java.html.BrwsrCtx;
|
||||
import net.java.html.js.JavaScriptBody;
|
||||
import org.jbox2d.collision.shapes.CircleShape;
|
||||
import org.jbox2d.collision.shapes.PolygonShape;
|
||||
import org.jbox2d.collision.shapes.Shape;
|
||||
import org.jbox2d.collision.shapes.ShapeType;
|
||||
import org.jbox2d.common.Vec2;
|
||||
import org.jbox2d.dynamics.Body;
|
||||
import org.jbox2d.dynamics.Fixture;
|
||||
import org.teavm.samples.benchmark.Scene;
|
||||
|
||||
public final class BenchmarkStarter {
|
||||
private BenchmarkStarter() {
|
||||
}
|
||||
|
||||
private static final Timer TIMER = new Timer("Make Step");
|
||||
private static final Scene scene = new Scene();
|
||||
private static double startMillisecond;
|
||||
private static int currentSecond;
|
||||
private static double timeSpentCalculating;
|
||||
private static BrwsrCtx ctx;
|
||||
|
||||
public static void main(String[] args) {
|
||||
startMillisecond = System.currentTimeMillis();
|
||||
ctx = BrwsrCtx.findDefault(BenchmarkStarter.class);
|
||||
makeStep();
|
||||
}
|
||||
|
||||
static void makeStep() {
|
||||
ctx.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
makeStep0();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void makeStep0() {
|
||||
double start = System.currentTimeMillis();
|
||||
scene.calculate();
|
||||
double end = System.currentTimeMillis();
|
||||
int second = (int)((System.currentTimeMillis() - startMillisecond) / 1000);
|
||||
if (second > currentSecond) {
|
||||
publishResults(second, timeSpentCalculating);
|
||||
timeSpentCalculating = 0;
|
||||
currentSecond = second;
|
||||
}
|
||||
timeSpentCalculating += end - start;
|
||||
render();
|
||||
TIMER.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
makeStep();
|
||||
}
|
||||
}, scene.timeUntilNextStep());
|
||||
}
|
||||
|
||||
private static void render() {
|
||||
GraphicsContext2D context = HTML5Graphics.getOrCreate("benchmark-canvas");
|
||||
context.setFillStyle(new Style.Color("white"));
|
||||
context.setStrokeStyle(new Style.Color("grey"));
|
||||
context.fillRect(0, 0, 600, 600);
|
||||
context.save();
|
||||
context.translate(0, 600);
|
||||
context.scale(1, -1);
|
||||
context.scale(100, 100);
|
||||
context.setLineWidth(0.01);
|
||||
for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) {
|
||||
Vec2 center = body.getPosition();
|
||||
context.save();
|
||||
context.translate(center.x, center.y);
|
||||
context.rotate(body.getAngle());
|
||||
for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
|
||||
Shape shape = fixture.getShape();
|
||||
if (shape.getType() == ShapeType.CIRCLE) {
|
||||
CircleShape circle = (CircleShape)shape;
|
||||
context.beginPath();
|
||||
context.arc(circle.m_p.x, circle.m_p.y, circle.getRadius(), 0, Math.PI * 2, true);
|
||||
context.closePath();
|
||||
context.stroke();
|
||||
} else if (shape.getType() == ShapeType.POLYGON) {
|
||||
PolygonShape poly = (PolygonShape)shape;
|
||||
Vec2[] vertices = poly.getVertices();
|
||||
context.beginPath();
|
||||
context.moveTo(vertices[0].x, vertices[0].y);
|
||||
for (int i = 1; i < poly.getVertexCount(); ++i) {
|
||||
context.lineTo(vertices[i].x, vertices[i].y);
|
||||
}
|
||||
context.closePath();
|
||||
context.stroke();
|
||||
}
|
||||
}
|
||||
context.restore();
|
||||
}
|
||||
context.restore();
|
||||
}
|
||||
|
||||
@JavaScriptBody(args = { "second", "timeSpentCalculating" }, body =
|
||||
"var resultTableBody = document.getElementById('result-table-body');\n" +
|
||||
"var row = document.createElement(\"tr\");\n" +
|
||||
"resultTableBody.appendChild(row);\n" +
|
||||
"var secondCell = document.createElement(\"td\");\n" +
|
||||
"row.appendChild(secondCell);\n" +
|
||||
"secondCell.appendChild(document.createTextNode(second));\n" +
|
||||
"var timeCell = document.createElement(\"td\");\n" +
|
||||
"row.appendChild(timeCell);\n" +
|
||||
"timeCell.appendChild(document.createTextNode(timeSpentCalculating));\n"
|
||||
)
|
||||
private static native void publishResults(int second, double time);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<!--
|
||||
Copyright 2014 Alexey Andreev.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||
<title>HotSpot/JavaFX jbox2d benchmark</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>HotSpot/JavaFX performance</h1>
|
||||
<div>
|
||||
<canvas id="benchmark-canvas" width="600" height="600"></canvas>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Second</th>
|
||||
<th>Time spent computing, ms</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="result-table-body">
|
||||
</tbody>
|
||||
</table>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user