Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The Rhino engine is actually capable of compiling scripts into bytecode 'in-process', so you don't need to run the tool to generate .class files first. You only need to set 'optimisation level' and the engine will automatically pre-compile the script before executing it. One way to override the optimisation level is with the VM argument -Drhino.opt.level. Set this to anything between 0 and 9 and run your original test program and you should see better performance. </p> <p>This is the same optimisation setting used by the compiling tool you mentioned, by the way. <a href="https://developer.mozilla.org/en-US/docs/Rhino/Optimization" rel="noreferrer">https://developer.mozilla.org/en-US/docs/Rhino/Optimization</a></p> <p>For total control of optimisation level and javascript version within your program, you can do the following. However you lose some of the trimmings that RhinoScriptEngine class (which is just a environment wrapper and not the javascript engine) provides. One such trimming is the 'print' function which is actually injected by said wrapper. For test purposes you can just replace 'print' with 'java.lang.System.out.print'.</p> <pre><code> int optimisationLevel = 3; int languageVersion = Context.VERSION_1_7; try { Context cx = Context.enter(); cx.setOptimizationLevel(optimisationLevel); cx.setLanguageVersion(languageVersion); ImporterTopLevel scope = new ImporterTopLevel(cx); cx.evaluateString(scope, TEST_SCRIPT1, "doTest", 1, null); for (int i = 0; i &lt; 10; i++) cx.evaluateString(scope, "doTest();", "", 1, null); } finally { Context.exit(); } </code></pre> <p>You mentioned the following:</p> <blockquote> <p>Note: some sources mention that Rhino engine runs compiled script roughly 1.6 slower than the "same" code written directly in Java. Not sure if "compilation of script" used in this sample the is same one which is supposed there.</p> </blockquote> <p>I'd be interested in the source that reported this, My fibonacci function in java takes about 1/30 the time as the compiled js implementation. But perhaps I'm missing something.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload