Jx浏览器6.23比6.21慢吗?

时间:2019-03-12 15:18:55

标签: javascript java performance javafx jxbrowser

我是JavaFx和JavaScripting的新手

我的JavaFx应用程序(显示HTML / JavaScript页面)可测量不同版本的JX浏览器的性能。

当我手动执行 Run 按钮时,似乎JX Bowser 6.23的速度比6.21慢。

我在做什么错?我应该怎么做才能提高性能。

版本(6.23)-10次执行时间(以毫秒为单位) 3879,3637,4483,3583,3565,3656,3748,3834,3895,3799

中位数3773.5,平均3807.9,最大4483,最小3565

版本(6.21)-10次执行时间(以毫秒为单位) 3581、3326、3257、3273、3217、3299、3284、3304、3352、3323

中位数3301.5,平均3321.6,最大3581,最小3217

示例代码如下:

JavaFX代码

sample.fxml

<?import javafx.scene.layout.AnchorPane?>
<AnchorPane fx:id="pane" fx:controller="sample.Controller"
            xmlns:fx="http://javafx.com/fxml">
</AnchorPane>

Main.java

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Test JX Browser Performance");
        primaryStage.setScene(new Scene(root, 1800, 1000));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

Controller.java

public class Controller implements Initializable {

    private static final Logger LOGGER = LogManager.getLogger(Controller.class);

    @FXML
    public AnchorPane pane;

    public static String pagePath = new File("src/sample/html/testJXBrowserCode.html").getAbsolutePath();;

    public void initialize(URL location, ResourceBundle resources) {
        BrowserPreferences.setChromiumSwitches(
                "--enable-experimental-canvas-features=true",
                "--num-raster-threads=4",
                "--max-tiles-for-interest-area=512",
                "--disable-web-security",
                "--allow-file-access-from-files",
                "--headless",
                "--remote-debugging-port=9222");

        final Browser browser = new Browser();
        final BrowserView browserView = new BrowserView(browser);
        pane.getChildren().add(browserView);

        AnchorPane.setTopAnchor(browserView, 0.0);
        AnchorPane.setBottomAnchor(browserView, 0.0);
        AnchorPane.setLeftAnchor(browserView, 0.0);
        AnchorPane.setRightAnchor(browserView, 0.0);

        final String url = "file://" + pagePath;
        browser.loadURL(url);

    }
}

pom.xml (用于测试jxbrowser版本在6.21和6.23之间切换)

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>groupId</groupId>
    <artifactId>version-test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>VersionTest</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.7</version>
        </dependency>

        <dependency>
            <groupId>com.teamdev.jxbrowser</groupId>
            <artifactId>jxbrowser</artifactId>
            <version>6.21</version>
        </dependency>

        <dependency>
            <groupId>com.teamdev.jxbrowser</groupId>
            <artifactId>jxbrowser-win64</artifactId>
            <version>6.21</version>
        </dependency>

        <dependency>
            <groupId>com.teamdev.jxbrowser</groupId>
            <artifactId>jxbrowser-licence</artifactId>
            <version>6.21</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>15.0</version>
            <exclusions>
                <exclusion>
                    <artifactId>com.google.code.findbugs</artifactId>
                    <groupId>jsr305</groupId>
                </exclusion>
            </exclusions>
        </dependency>

    </dependencies>
</project>

HTML / JavaScript

testJXBrowserCode.html

<!DOCTYPE html>
<html lang="en">
<head>

    <script src="lib/jquery-3.1.1.min.js"></script>

    <meta charset="UTF-8">
    <title>Test JX Browser Performance</title>
</head>
<body>
<div class="container">
    <div>
        <button onclick="run()">Run</button>
    </div>
    <div>
        <div>
            <a class="displayText">TEST</a>
        </div>
        <div>
            <a class="complete"></a>
        </div>
        <div>
            <a class="startTime"></a>
        </div>
        <div>
            <a class="endTime"></a>
        </div>
    </div>


    <script type="text/javascript">
        function run() {
            console.log("run");
            var startTime = Date.now();
            $(".startTime").text("Start time " + startTime);

            for (var i = 0; i < 99999; i++) {
                $(".displayText").text("hello " + i);
                console.log(i);
            }

            var endTime = Date.now();
            $(".endTime").text("Start time " + endTime);

            $(".complete").text("Total time taken " + (endTime - startTime));
        }
    </script>
</div>

</body>
</html>

0 个答案:

没有答案