Adding FX WebView based sample to demonstrate the performance when running on top of HotSpot VM. Use following command to try:

teavm-samples/teavm-samples-benchmark$ mvn clean install && mvn -Pfx exec:java
This commit is contained in:
Jaroslav Tulach 2015-02-26 12:04:51 +01:00
parent 3bb171e4a1
commit cf8645decf
4 changed files with 136 additions and 11 deletions

View File

@ -76,6 +76,11 @@
<artifactId>html5-canvas</artifactId>
<version>0.7.1</version>
</dependency>
<dependency>
<groupId>org.netbeans.html</groupId>
<artifactId>net.java.html.boot</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<build>
@ -194,10 +199,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.bck2brwsr.BenchmarkFX</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -0,0 +1,29 @@
/*
* Copyright 2015 jarda.
*
* 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.bck2brwsr;
import net.java.html.boot.BrowserBuilder;
public class BenchmarkFX {
public static void main(String... args) {
BrowserBuilder.newBrowser().loadPage("fx.html")
.loadClass(BenchmarkStarter.class)
.invoke("main")
.showAndWait();
System.exit(0);
}
}

View File

@ -20,6 +20,8 @@ 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;
@ -35,28 +37,30 @@ public class BenchmarkStarter {
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();
}
private static void 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) {
/*
HTMLElement row = document.createElement("tr");
resultTableBody.appendChild(row);
HTMLElement secondCell = document.createElement("td");
row.appendChild(secondCell);
secondCell.appendChild(document.createTextNode(String.valueOf(second)));
HTMLElement timeCell = document.createElement("td");
row.appendChild(timeCell);
timeCell.appendChild(document.createTextNode(String.valueOf(timeSpentCalculating)));
*/
publishResults(second, timeSpentCalculating);
timeSpentCalculating = 0;
currentSecond = second;
}
@ -109,4 +113,17 @@ public class BenchmarkStarter {
}
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);
}

View File

@ -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>