How is the Kotlin Playground so fast?

I’m comparing the speed of a hello world example running locally and on kotlin playground:

import java.util.*;

fun main(args: Array<String>) {
  for (i in 1..10) println("Hello, World!")

Running it on takes around 1.5 seconds
Compiling it locally with kotlinc (1.3.31) and running the jar with java 11 takes around 7 seconds

How is it possible that the playground is so much faster? Is it only the hardware?

The Kotlin compiler can run as a deamon, which it probably does on Kotlin playground. This removes the time costs of starting up the compiler.

Also in order to run application you need to startup JVM two times: one for compile and one for run.

1 Like