mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Merge pull request #83 from jtulach/HotSpotBenchmark
Modifying the benchmark to run on HotSpot
This commit is contained in:
commit
8b168b53eb
23
teavm-samples/teavm-samples-benchmark/README.md
Normal file
23
teavm-samples/teavm-samples-benchmark/README.md
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
TeaVM, GWT, HotSport JBox2D Benchmark
|
||||||
|
=====================================
|
||||||
|
|
||||||
|
Compares the speed of execution on a complex [JBox2D](http://www.jbox2d.org/) CPU extensive
|
||||||
|
computation. JavaScript produced by TeaVM and GWT can be compared by running
|
||||||
|
|
||||||
|
```
|
||||||
|
$ mvn clean install
|
||||||
|
```
|
||||||
|
|
||||||
|
then just open the generated HTML versions
|
||||||
|
|
||||||
|
```
|
||||||
|
$ open target/teavm-samples-benchmark-*-SNAPSHOT/index.html
|
||||||
|
```
|
||||||
|
|
||||||
|
In addition to that one can run the same demo with classical HotSpot virtual machine. Just try:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ mvn -Pfx exec:java
|
||||||
|
```
|
||||||
|
|
||||||
|
|
|
@ -33,16 +33,19 @@
|
||||||
<groupId>org.teavm</groupId>
|
<groupId>org.teavm</groupId>
|
||||||
<artifactId>teavm-classlib</artifactId>
|
<artifactId>teavm-classlib</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.teavm</groupId>
|
<groupId>org.teavm</groupId>
|
||||||
<artifactId>teavm-jso</artifactId>
|
<artifactId>teavm-jso</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.teavm</groupId>
|
<groupId>org.teavm</groupId>
|
||||||
<artifactId>teavm-dom</artifactId>
|
<artifactId>teavm-dom</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jbox2d</groupId>
|
<groupId>org.jbox2d</groupId>
|
||||||
|
@ -54,6 +57,7 @@
|
||||||
<artifactId>jbox2d-library</artifactId>
|
<artifactId>jbox2d-library</artifactId>
|
||||||
<version>2.2.1.1</version>
|
<version>2.2.1.1</version>
|
||||||
<classifier>sources</classifier>
|
<classifier>sources</classifier>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.gwt</groupId>
|
<groupId>com.google.gwt</groupId>
|
||||||
|
@ -61,6 +65,16 @@
|
||||||
<version>2.7.0</version>
|
<version>2.7.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -77,43 +91,69 @@
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.teavm</groupId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<artifactId>teavm-maven-plugin</artifactId>
|
<version>2.5</version>
|
||||||
<version>${project.version}</version>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>web-client</id>
|
<phase>prepare-package</phase>
|
||||||
<phase>prepare-package</phase>
|
<goals>
|
||||||
<goals>
|
<goal>jar</goal>
|
||||||
<goal>build-javascript</goal>
|
</goals>
|
||||||
</goals>
|
<configuration>
|
||||||
<configuration>
|
<archive>
|
||||||
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
<manifest>
|
||||||
<mainClass>org.teavm.samples.benchmark.teavm.BenchmarkStarter</mainClass>
|
<mainClass>org.teamvm.samples.benchmark.htmljava.BenchmarkStarter</mainClass>
|
||||||
<runtime>SEPARATE</runtime>
|
<addClasspath>true</addClasspath>
|
||||||
<minifying>true</minifying>
|
<classpathPrefix>lib/</classpathPrefix>
|
||||||
<debugInformationGenerated>true</debugInformationGenerated>
|
<useUniqueVersions>false</useUniqueVersions>
|
||||||
</configuration>
|
</manifest>
|
||||||
</execution>
|
</archive>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/gwt/*</exclude>
|
||||||
|
<exclude>**/teavm/*</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.teavm</groupId>
|
||||||
<artifactId>gwt-maven-plugin</artifactId>
|
<artifactId>teavm-maven-plugin</artifactId>
|
||||||
<version>2.7.0</version>
|
<version>${project.version}</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<id>web-client</id>
|
||||||
<goal>compile</goal>
|
<phase>prepare-package</phase>
|
||||||
</goals>
|
<goals>
|
||||||
<configuration>
|
<goal>build-javascript</goal>
|
||||||
<optimizationLevel>9</optimizationLevel>
|
</goals>
|
||||||
<compileSourcesArtifacts>
|
<configuration>
|
||||||
<item>org.jbox2d:jbox2d-library</item>
|
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
||||||
</compileSourcesArtifacts>
|
<mainClass>org.teavm.samples.benchmark.teavm.BenchmarkStarter</mainClass>
|
||||||
</configuration>
|
<runtime>SEPARATE</runtime>
|
||||||
</execution>
|
<minifying>false</minifying>
|
||||||
</executions>
|
<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>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
@ -127,10 +167,47 @@
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
</plugin>
|
</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>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</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>
|
</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