Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • A Comparison of Compilation Speed of Kotlin Vs JAVA

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 1.52k
    Comment on it

    Java has become the reference language when it comes to programming applications for Android, but serious rivals have arisen, from C++ to Scala. One of those competitors is Kotlin, a language that was conceived and started to be developed in 2011 by JetBrains. They had 70% of their products written in Java, but they started looking for alternatives, due to the excessive lengths of Java codes. And for that, they decided to create their own language.

     

    This is how Kotlin was born, whose first stable version was launched in February 2016. It has been gaining ground, and is already ranked 31 in the respected TIOBE index, while Java is still at the top as number 1. Kotlin is already supported officially by Android Studio, which boosted its growth.

     

    Indeed we can verify that Kotlin has several advantages like that it can convert Java code to Kotlin code without problems, and that it works perfectly with many less lines of code than Java. However, there remains an important question to be asked. Do you have a performance equal to or better than Java?

     

     

    Testing

    A writer from Medium (https://medium.com/@ajalt/kotlin-vs-java-compilation-speed-e6c174b39b5d) wrote an article about it comparing Kotlin compilation speeds in 2016. The author wrote shell scripts to run compilations in Gradle repeatedly in various scenarios. Each test was performed 10 consecutive times, cleaning the project before each scenario.

     

    The author made his first tests running a clean compilation from a cold start, disabling the Gradle daemon. According to this scenario, Java compilation times averaged 15.5 seconds, while Kotlin averaged 18.5 seconds. This means that Java is 15-20% faster in clean compilations without Gradle.

     

    Later, the author did the same tests but with the Gradle daemon running. In these cases, a clean compilation in Java averaged 14.1 seconds, while Kotlin recorded 16.5 seconds, which means a 10-15% advantage for Java.

     

    Of course, this doesn't mean much, since most programmers don´t compile like this. It's more common to compile the same base code several times when making changes. And precisely for that scenario the Gradle daemon was designed.

     

    Java needs to start and stop the JVM every time it compiles, losing the performance gain for each repeated compilation. Gradle was created to avoid that need, keeping the performance gains of the compiler with its daemon.

     

    However, the really important factor of a compiler is the performance of its incremental compilation. A normal compilation will recompile all the files in the project, but the incremental compilation will only recompile the modified files, which improves performance.

     

    The author then did several incremental compilation tests comparing Kotlin with Java using several scenarios. The results were that although the Gradle daemon delays two or three executions to work at maximum, the results of both languages end up being very similar. When changing a file that is not being used by any other file, Java has an average of 7 seconds and Kotlin records 6.1 seconds. Without modified files, Java takes 4.6 seconds compiling and Kotlin averages 4.5 seconds. In case of changing a file that is used by other files in the project, Java requires 7.1 seconds to compile, and Kotlin averages 6 seconds.

     

    Conclusion

    In summary, after the comparative evaluation by the author, we can say that despite the advantage of Java in clean compilations, those are little used by the average programmer, while in partial compilations, where it is usual to use incremental compilation, Kotlin compiles as fast as Java.

     

    Undoubtedly, Kotlin is a language with future and totally recommendable.

    A Comparison of Compilation Speed of Kotlin Vs JAVA

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: