title: Why is it faster to call external scala compiler than use the runtime interpreter library?
body: <p>Why is it faster to call external scala compiler than use the runtime interpreter library?
  In the code below <strong>it takes almost 2s</strong> to warm up the interpreter.</p>
  
  <pre><code>val out = new PrintStream(new FileOutputStream("/dev/null"))
  val flusher = new java.io.PrintWriter(out)
  val interpret = {
     val settings = new scala.tools.nsc.GenericRunnerSettings(println _)
     settings.usejavacp.value = true
     new scala.tools.nsc.interpreter.IMain(settings, flusher)
  }
  interpret.interpret(" ") //   &lt;-- warming up
  interpret.interpret(" Hello World ")
  </code></pre>
  
  <p>In the other hand, when running Scala compiler from command line like in a shell session:</p>
  
  <pre><code>scala HelloWorld.scala
  </code></pre>
  
  <p>it takes <strong>less than 0.5s</strong> to print a Hello World.</p>
  
  <p>I am trying to parse+execute some Java, Scala or similar code given in a string during runtime (it is a script interpreter, i.e. it will be run only one time during my app execution).
  Scala code  would be better obviously, but only if it can be as fast as the Java option.
  <strong>Is there any faster alternative than nsc.interpreter and external compiler to execute code from a string at runtime?</strong>
  The best I could found was Janino; it is faster than Scala compiler and does not require the JDK (a very interesting feature).</p>
  
  <p>As a last resource, how fast are <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/" rel="nofollow">Java Scripting Engines</a> compared to a reflected or bytecode-compiled Java code? I found that, at least, they can be compiled: <a href="http://www.ibm.com/developerworks/library/j-5things9/" rel="nofollow">Compiling oft-used scripts</a>.</p>
  
  <hr>
  
  <hr>
  
  <p><strong>Chosen solution:
  <a href="https://eknet.org/main/dev/runtimecompilescala.html" rel="nofollow">runtimecompilescala</a></strong>.</p>