11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Nashorn(Java 8のJavaScriptエンジン)の実力

Last updated at Posted at 2014-03-22

Java 8 になって、JREに含まれるJavaScriptエンジンがRhinoからNashornに変わりました。

public class Inspector {
    public static void main(String[] args) {
        ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("js");
        System.out.println("engine = " + engine);
    }
}

engine = jdk.nashorn.api.scripting.NashornScriptEngine@548ad73b

速くなったのかなー?ということで、RhinoとNashhornの実行速度を比較してみます。
コードはこんなシンプルなものです。

public class Inspector {
    public static void main(String[] args) throws ScriptException {
        ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("js");
        System.out.println("engine = " + engine);
        long startTime = System.currentTimeMillis();
        engine.eval("var count = 0;for(var i=0;i<100000;i++){count += i}");
        System.out.println("finish "+(System.currentTimeMillis() - startTime));
    }
}

java7で実行すると、

engine = com.sun.script.javascript.RhinoScriptEngine@4fb3c3d9
finish 367

java8で実行すると、

engine = jdk.nashorn.api.scripting.NashornScriptEngine@548ad73b
finish 117

Nashoneはやーい。

11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?